Linux Commands
There are some basic Linux commands with
their arguments and functions:
1. `ls`: List directory contents
- `-a`: List all files, including hidden files.
- `-l`: Use a long listing format that includes file
permissions, ownership, size, and modification date.
- `-h`: Use human-readable file sizes.
2. `cd`: Change directory
- `<directory>`: Change to the specified directory.
- `~`: Change to the home directory.
- `-`: Change to the previous directory.
3. `pwd`: Print working directory
- No arguments.
4. `mkdir`: Make directory
- `<directory>`: Create a directory with the specified name.
- `-p`: Create parent directories if they don't exist.
5. `rmdir`: Remove directory
- `<directory>`: Remove the specified directory.
- `-p`: Remove parent directories if they are empty.
6. `cp`: Copy files or directories
- `<source>` `<destination>`: Copy the source file or directory
to the destination.
- `-r`: Copy directories recursively.
- `-i`: Prompt before overwriting existing files.
7. `mv`: Move or rename files or directories
- `<source>` `<destination>`: Move the source file or directory
to the destination.
- `-i`: Prompt before overwriting existing files.
8. `rm`: Remove files or directories
- `<file>`: Remove the specified file.
- `-r`: Remove directories and their contents recursively.
- `-f`: Force removal without prompting.
9. `cat`: Concatenate and print files
- `<file>`: Display the contents of the specified file.
- `-n`: Number the output lines.
10. `less`: Display file contents page by page
- `<file>`: Display the contents of the specified file.
- `SPACE`: Scroll forward one screen.
- `b`: Scroll backward one screen.
11. `head`: Display first lines of a file
- `<file>`: Display the first 10 lines of the specified file.
- `-n`: Specify the number of lines to display.
12. `tail`: Display last lines of a file
- `<file>`: Display the last 10 lines of the specified file.
- `-n`: Specify the number of lines to display.
- `-f`: Output appended data as the file grows.
13. `grep`: Search file for lines matching a pattern
- `<pattern>` `<file>`: Search for lines that match the
specified pattern in the specified file.
- `-i`: Ignore case when searching.
- `-r`: Search recursively through directories.
14. `find`: Search for files in a directory hierarchy
- `<directory>` `-name <pattern>`: Search for files in the
specified directory that match the specified pattern.
- `-type <type>`: Search for files of the specified type (`f`
for regular files, `d` for directories, `l` for symbolic links).
15. `chmod`: Change file permissions
- `<mode>` `<file>`: Change the permissions of the specified
file to the specified mode (e.g. `chmod 644 file.txt`).
- `-R`: Change permissions recursively for directories and
their contents.
16. `chown`: Change file ownership
- `<user>` `<file>`: Change the owner of the specified file to
the specified user.
- `-R`: Change ownership recursively for directories and their
contents.
17. `ps`: Display information about running processes
- No arguments: Display information about processes owned by
the current user.
- `-e`: Display information about all processes.
- `-f`: Use a full listing format that includes process
details.
18. `kill`: Send a signal to a process
- `<pid>`: Send the default signal (`SIGTERM`) to the process
with the specified process ID.
- `-s <signal>` `<pid>`: Send the specified signal to the
process with the specified process ID.
19. `top`: Display system resource usage and processes
- No arguments: Display resource usage and process information
in real time.
- `-u <user>`: Display resource usage and process information
for the specified user.
- `-p <pid>`: Display resource usage and process information
for the specified process ID.
20. `df`: Display disk space usage
- No arguments: Display disk space usage for all mounted file
systems.
- `-h`: Use human-readable file sizes.
- `-T`: Display file system type.
21. `du`: Display disk usage of files and directories
- `<file or directory>`: Display disk usage of the specified
file or directory.
- `-h`: Use human-readable file sizes.
- `-s`: Display summary only.
22. `tar`: Manipulate archive files
- `c`: Create a new archive file.
- `x`: Extract files from an archive file.
- `t`: List the contents of an archive file.
- `f`: Use the specified file as the archive file.
- `z`: Compress or decompress files using gzip.
- `j`: Compress or decompress files using bzip2.
23. `gzip`: Compress files using the gzip algorithm
- `<file>`: Compress the specified file.
- `-d`: Decompress the specified file.
- `-k`: Keep the original file after compressing or
decompressing.
24. `gunzip`: Decompress files compressed with gzip
- `<file>`: Decompress the specified file.
- `-k`: Keep the original file after decompressing.
25. `ssh`: Connect to a remote host over SSH
- `<user>@<host>`: Connect to the specified host as the
specified user.
- `-p <port>`: Use the specified port for the SSH connection.
26. `scp`: Copy files between hosts over SSH
- `<source>` `<destination>`: Copy the source file or
directory to the destination over SSH.
- `-r`: Copy directories recursively.
- `-P <port>`: Use the specified port for the SSH connection.
27. `rsync`: Copy files between hosts efficiently
- `<source>` `<destination>`: Copy the source file or
directory to the destination.
- `-r`: Copy directories recursively.
- `-a`: Preserve file permissions and ownership.
- `-v`: Verbose output.
28. `ping`: Test network connectivity to a host
- `<host>`: Test network connectivity to the specified host.
- `-c <count>`: Send the specified number of packets.
- `-i <interval>`: Wait the specified number of seconds
between packets.
29. `ifconfig`: Configure network interfaces
- No arguments: Display network interface configuration.
- `<interface>` `<address>`: Configure the specified network
interface with the specified IP address.
- `up`: Enable the specified network interface.
30. `route`: Display or modify the routing table
- No arguments: Display the routing table.
- `add <network> gw <gateway>`: Add a route to the specified
network via the specified gateway.
- `del <network>`: Delete the route to the specified network.
31. `netstat`: Display network connections and statistics
- No arguments: Display active network connections.
- `-a`: Display all network connections, including listening
sockets.
- `-r`: Display the routing table.
32. `iptables`: Configure firewall rules
- `<chain>` `<rule>`: Add a rule to the specified chain (e.g.
`iptables INPUT -p tcp --dport 22 -j ACCEPT`).
- `-L`: List the current firewall rules.
- `-F`: Flush all firewall rules.
33. `systemctl`: Control the systemd system and service manager
- `start <service>`: Start the specified service.
- `stop <service>`: Stop the specified service.
- `restart <service>`: Restart the specified service.
- `status <service>`: Display the status of the specified
service.
34. `journalctl`: Query the systemd journal
- No arguments: Display all log messages in the journal.
- `-u <unit>`: Display log messages for the specified systemd
unit.
- `-f`: Follow the journal in real time.
35. `passwd`: Change user password
- No arguments: Change the password for the current user.
- `<user>`: Change the password for the specified user.
36. `useradd`: Add a new user account
- `<user>`: Create a new user account with the specified
username.
- `-m`: Create a home directory for the new user.
37. `userdel`: Delete a user account
- `<user>`: Delete the specified user account.
- `-r`: Remove the user's home directory and mail spool.
38. `groupadd`: Add a new group
- `<group>`: Create a new group with the specified name.
39. `groupdel`: Delete a group
- `<group>`: Delete the specified group.
40. `sudo`: Execute a command with superuser privileges
- `<command>`: Execute the specified command with superuser
privileges.
- `-u <user>`: Execute the command as the specified user.
41. `su`: Switch to another user account
- `<user>`: Switch to the specified user account.
- `-`: Switch to the specified user account and its
environment.
42. `whoami`: Display current user name
- No arguments.
43. `hostname`: Display or set the system hostname
- No arguments: Display the current hostname