To work a Linux machine remotely, such as a virtual private server (VPS) or a server, system administrators mainly use a command-line interface (CLI). Even though some Linux machines offer visual interfaces, such as buttons and windows (GUI), to control basic actions on a server. Still, a command-line interface (CLI) lets system administrators use commands to manage the server more efficiently and flexibly. To utilise Linux commands on a remote server, you must connect via SSH using PuTTY or Terminal.
However, using the command-line interface, commonly the bash shell, can be tricky because Linux has many commands for different jobs. To help you get started, we’ll introduce you to 75 important Linux commands for managing your remote VPS or Servers.
This article lists 75 essential Linux commands. These commands are grouped into categories for easy reference and cover various tasks, from basic file and directory management to advanced network administration and scripting.
Overview of the 75 essential Linux commands:
- 1. ls: List directory contents.
- 2. cd: Change directory.
- 3. mkdir: Create a directory.
- 4. rmdir: Remove an empty directory.
- 5. rm: Delete a file or directory (use with caution!).
- 6. cp: Copy a file or directory.
- 7. mv: Move or rename a file or directory.
- 8. file: Display the type of a file.
- 9. cat: To concatenate, and display files.
- 10. head: Display the first few lines of a file.
- 11. tail: Display the last few lines of a file.
- 12. pwd: Prints the Present Working Directory
- 13. wc: To count lines, words, and characters in a file.
- 14. touch: Creates new empty files
- 15. grep: Search for patterns in text files.
- 16. tar: Create and extract compressed archives.
- 17. less: View a file one page at a time.
- 18. more: View a file one page at a time (similar to less).
- 19. find: Search files and directories for name, type, size, modification time or more.
- 20. diff: Compare two files and show their differences.
- 21. nano: Edit text files.
- 22. vim: Edit text files (advanced).
- 23. tee: Writes the output of a command to both a file and the standard output.
- 24. awk: Scripting language for processing text files.
- 25. sed: Perform text manipulation and substitution.
- 26. locate: Quickly find files by name using a pre-built database (updated regularly by a system service).
- 27. cut: Extract specific columns from a text file.
- 28. sort: Sort lines of text.
- 29. sudo: Run a command with root privileges.
- 30. chmod: Change file and directory permissions (control who can read, write, or execute them).
- 31. su: Switch to another user.
- 32. uname: Show the currently logged-in user.
- 33. chown: Change file and directory ownership (assign them to different users or groups).
- 34. useradd, userdel: Purpose: Manage user accounts on the system.
- 35. passwd: Change your password.
- 36. groups: Show the groups you belong to.
- 37. top: Monitor system resource usage.
- 38. free: Show memory usage.
- 39. df: Show disk space usage.
- 40. ps: Show running processes.
- 41. kill: Terminate a running process.
- 42. reboot: Reboot the system.
- 43. du: Reports disk space usage for files and directories.
- 44. htop: Provides a real-time overview of system processes and resource usage.
- 45. hostname: Prints or sets the system’s hostname
- 46. time: Measures the execution time of a command or script.
- 47. systemctl: Manages systemd services and units.
- 48. watch: Executes a command repeatedly, displaying its output in real-time.
- 49. jobs: Lists currently running background jobs in the shell.
- 50. whoami: Prints the current user’s username.
- 51. id: Show your user ID and group ID.
- 52. shutdown: Shut down the system.
- 53. ping: Test network connectivity to a host.
- 54. traceroute: Attempts to trace the route taken by packets (IP) to a host.
- 55. netstat: Show network connections and statistics.
- 56. ifconfig: Show network interface configuration.
- 57. route: Show and manipulate the routing table.
- 58. wget: Download files from the internet.
- 59. curl: Transfer data over the internet.
- 60. scp: Securely copies files between hosts using SSH.
- 61. rsync: synchronizes files and directories between hosts.
- 62. nslookup: resolve hostnames and IP addresses
- 63. dig: DNS lookup tool with more options than nslookup
- 64. gzip: For compress files to reduce their size.
- 65. gunzip: Decompress files compressed with gzip.
- 66. zip: Create compressed archives in ZIP format.
- 67. unzip: Extract files from ZIP archives.
- 68. apt-get: Install, remove, and manage software packages.
- 69. yum: Package manager for RPM-based systems
- 70. pacman: Lightweight and simple package manager.
- 71. alias: Create custom aliases for frequently used commands.
- 72. history: Show your command history.
- 73. man: Show the manual page for a command.
- 74. which: Find the location of a command.
- 75. whereis: Find the location of a command or file.
Now let’s check each command listed above and understand the usage of each Linux command.
File and Directory Management Linux Commands
In this section will discover the basic Linux commands used for file and directory management.
1. ls command
The ls command lists current directory contents. With the ls command, you can see the files and folders within the current directory or a specified directory. Use ls -l for a more detailed listing with file permissions and sizes.
Syntax for ls command:
ls [/directory/folder/path]
Other Options with the ls command:
Add the following options, to modify the command.
- -l: option provides a detailed listing that includes additional information such as file permissions, owner, group, file size, and modification date.
- -a: option includes hidden files and directories in the listing.
- -lh: option makes file sizes more human-readable by using units like KB, MB, or GB.
- -R: option lists files and directories recursively, displaying the contents of subdirectories as well.
- -lt: options sorts files by modification time, showing the most recently modified files first.
- -lr: option reverses the order of the listing, showing files in reverse order.
- -d */: option is used to list directories only.
2. cd command
The cd command is used for the Change directory. It means you can navigate through your file system using cd followed by the directory path.
Syntax for cd command:
cd /path/to/directory
Other Options with the cd command:
Add the following options, to modify the command.
- cd ..: This command permits you to move up one level in the directory hierarchy to the parent directory.
- cd – : This command lets you switch to the last working directory. It is useful for toggling between two directories.
- cd relative/path: This command changes the current working directory based on a relative path from the current location.
- cd $HOME: Environment variables can be used to represent paths. In this example, $HOME is the home directory of the current user.
- cd ~username: This command changes the current working directory to directory of the specified user.
- cd “directory with spaces”: If a directory name contains spaces, enclose the directory name in double quotes.
- cd –: This command moves to the previous directory in the shell history.
It is important to understand how to use it efficiently to move between directories and organise files and directories effectively.
3. mkdir command
The mkdir command is used for creating a one or multiple directories and along with their permissions. Use mkdir followed by the directory name to create a new folder.
Syntax for mkdir command:
mkdir [options] directory_name
Other Options with the mkdir command:
Add the following options, to modify the command
- -p: Create parent directories as needed.
- -m: Set permissions for the directory.
- -v: Be verbose, print a message for each created directory.
4. rmdir command
The command rmdir is used to remove an empty directories (folders). It stands for “remove directory” and it works only if the directory is empty. Use rmdir followed by the directory path to delete an empty folder. Be careful, as this cannot be undone!
Syntax for rmdir command:
rmdir [options] directory_name
Other Options with the rmdir command:
Add the following options, to modify the command.
- -p: Remove parent directories as well. This option allows rmdir to remove the particular directory (folder) and its parent directories if they become empty after the removal.
- –ignore-fail-on-non-empty: Ignore directories that are not empty and continue removing other directories.
Note:
- rmdir will not remove a directory(folder) if it contains any files or subdirectories. For non-empty directories, you should use the rm command with the -r (recursive) option.
5. mv command
The command mv is used to moves or renames a file or directory. Use mv followed by the old and new names or paths. For example, mv file.txt new_file.txt renames the file, and mv file.txt ../folder moves the file to the folder named “folder” one level up.
Syntax for mv command:
mv [options] source destination
Other Options with the mv command:
Add the following options, to modify the command
- -i: It means Interactive mode. Prompt before overwriting files.
- -u: It stands for Update. Allows to move only when the source file is new or the destination file is missing.
- -b: Allow to create a backup of the destination file before overwriting.
- -n: It means No clobber. It doesn’t allow to overwrite an existing file.
- –backup[=CONTROL]: Make backups according to the specified CONTROL. The possible values for CONTROL are:
- none or off: No backups.
- numbered or t: Make numbered backups.
- existing or nil: Make numbered backups of files that already have them, simple backups of the others.
6. cp command
The cp command allows to copy a file or directory. Use cp followed by the source and destination paths. For example, cp file.txt backup.txt creates a copy of the file named “backup.txt”.
Syntax for cp command:
cp [options] source destination
Other Options with the cp command:
Add the following options, to modify the command
- -u: Enables to copy only when the source file is new than the destination file or when the destination file is missing.
- -r or -R: Copy directories and their contents recursively.
- -a: Preserves the original file’s ownership, timestamps, and permissions.
- -l: Link. Create hard links instead of copying.
- -b: Allow to make a backup of each existing destination file.
7. rm command
The rm command is used to Delete file or directory (use with caution!). So, be very careful with the rm command, as it permanently deletes files and cannot be regained.
Syntax for rm command:
rm [options] file1 file2
Other Options with the rm command:
Add the following options, to modify the command
- -i: It stands for Interactive mode. Prompt before each removal.
- -f: It stands for Force. Ignore nonexistent files and do not prompt.
- -r or -R: It stands for Recursive. Remove directories and their contents recursively.
- –preserve-root: Do not remove / (root directory).
- –no-preserve-root: Allow removing / (root directory).
8. file command
The file command helps to display the type of a file. Use file followed by the filename to identify the file type, such as text, image, or executable.
Syntax for file command:
file [options] file1 file2
Other Options with the file command:
Add the following options, to modify the command
- -b: It stands for brief mode. Do not prepend filenames to output lines.
- -i: It stands for mime type. Instead of printing the file type, print the MIME type.
- –z: It stands for compressed files. Decompress the input files before trying to read them.
- -L: It stands for symbolic links. If a file is a symbolic link, follow the link and try to process the file to which the link points.
- -h or –help: Display help information.
- –version: Display version information.
9. cat command
The cat command is often used for displaying the content of files, combining files, or redirecting output to other files. You need to use command cat followed by the filename to view the file’s contents.
Syntax for cat command:
cat [options] file1 file2
Some examples of how to use the cat command:
1. To display the contents of a file:
cat filename.txt
2. To concatenate multiple files:
cat file1.txt file2.txt
3. To create a new file:
cat > newfile
4. To append content to an existing file:
cat >> existingfile
5. To redirect output to a file:
cat filename > outputfile
6. To view the content of a file in the terminal:
cat filename | more
Other Options with the cat command
Add the following options, to modify the command
- -A, –show-all: Prints out all the characters and is equivalent to -vET.
- -b, –number-nonblank: It shows non-blank output lines. Also, can be override using -n.
- -e: Equivalent to -vE.
- -E, –show-ends: Displays with a “$” at the end of each line.
- -n, –number: Display Number to all output lines.
- -s, –squeeze-blank: Suppress repeated empty output lines.
- -T, –show-tabs: Display TAB characters as ^I.
- -v, –show-nonprinting: It is use ^ and M- notation, except for LFD and TAB.
10. head command
The head command displays the first few lines of a file. Use head followed by the filename and a number (optional) to view the first few lines.
Syntax for head command:
head [options] file1 file2
Some examples of how to use the head command:
1. Display the first 10 lines of file
head -n 10 myfile.txt
2. Display first 500 bytes of a file
head -c 500 myfile.txt
3. Display the first 10 lines of multiple files
head -n 10 myfile1.txt myfile2.txt
Other Options with the head command
- -n: Displays the first N lines of each file. If no number is defined, it defaults to 10.
- -c: Displays the first N bytes or kilobytes of each file.
- -q, –quiet, –silent: Never print headers, even when more than one file is specified.
11. tail command
It is used to displays the last few lines of a file. Use tail followed by the filename and a number (optional) to view the last few lines; for example, tail -n 5 file.txt shows the last 5 lines.
Syntax for tail command:
tail [options] file1 file2 …
Some examples of how to use the tail command:
1. Display the last 20 lines of file
head -n 20 myfile.txt
2. Display last 300 bytes of a file
head -c 300 myfile.txt
3. Display the last 15 lines of multiple files
head -n 15 myfile1.txt myfile2.txt
Other Options with the tail command
- -n: Display the last N lines of each file. If no number is specified, it defaults to 10.
- -c: Display the last N bytes or kilobytes of each file.
- -f, –follow[={name|descriptor}]: Output appended data as the file grows.
- -q, –quiet, –silent: Never print headers, even when more than one file is specified.
12. pwd command
It’s a simple yet fundamental Linux command for understanding position within the file hierarchy. A pwd command prints the Present Working Directory, indicating the full path of your current location within the file system.
Syntax for pwd command:
pwd [option]
13. wc command
A wc command is used to counts lines, words, and characters in a file. Use wc followed by the filename to get a count of lines, words, and characters.
Syntax for wc command:
wc [options] file1 file2 …
Some examples of how to use the wc command:
1. To count lines, words, and characters in a file:
wc filename.txt
2. To count lines in multiple files:
wc -l file1.txt file2.txt
3. To count words in a file:
wc -w filename.txt
4. To count characters in a file:
wc -c filename.txt
5. To display the length of the longest line in a file:
wc -L filename.txt
Other Options with the wc command
- -l: Count lines only.
- -w: Count words only.
- -c: Count characters only.
- -m: Count characters, including newlines.
- -L: Display the length of the longest line.
14. touch command
A touch command is used to create empty files or to update the timestamps of existing files and directories.
15. grep command
A grep command is used to searches for patterns in text files. Use grep followed by the pattern and filename to find lines that match the pattern.
Syntax for grep command:
grep [options] pattern file1 file2 …
Other Options with the grep command
- -i: Ignore case distinctions.
- -n: Print the line number with output lines.
- -c: Print only the count of lines that contain the pattern.
- -l: Prints only the names of files that have the pattern.
- -r, -R: Recursively search subdirectories.
- -w: Match whole words.
16. tar command
A tar command is used to create and extract compressed archive files. Use tar to create archives (.tar) or extract them (.tar.gz, .zip).
Syntax for tar command:
tar [options] [file]
Other Options with the tar command
- Creating Archives:
- -c: Create a new archive.
- -f: Specify the archive file name.
- -v: Verbose mode, show progress and file names.
- -z: Use gzip compression.
- -j: Use bzip2 compression.
- -J: Use xz compression.
- -t: List the contents of an archive.
- -r: Append files to an existing archive.
- Extracting Archives:
- -x: Extract files from an archive.
- -C: Change to the specified directory before extracting.
Text Processing and Searching Linux Commands
The following section explores several Linux commands for processing and searching text.
17. less command
The less command is used to view and navigate(scroll up & down, search ) through the contents of a file. You will be able to view a file one page at a time.
Syntax for less command:
less [options] [file]
Other Options with the less command:
- -N: line numbers
- -f: follow the file as it grows
- -Q: quit if the file is read
- -S: chop long lines
18. more command
The less command is used to view a file one page at a time, similar to less but with fewer features.
Syntax for more command:
more [options] [file]
Other Options with more command:
- -d: helps to display prompt
- -s: used to squeeze multiple blank lines
- -f: helps to count lines
19. find command
A find command is a Linux command that searches for files and directories. It allows you to define various criteria to make searching for different tasks easier. The multiple criteria are based on name, location, modification time, size, permissions, and content.
Syntax for find command:
find [option] [path] [expression]
20. diff command
The diff command compares two files or directories line by line and highlights the differences between them.
Syntax for diff command:
diff [option] file1 file2
Other Options with diff command:
- -u: used to make it easier to read with context lines
- -y: for Side-by-side comparison.
- -i: To Ignore case differences.
- -w: To Ignore whitespace differences.
- -n: Number each line for easier reference.
21. jet, vi, nano command
The nano, jet, and vi are command-line text editors. They are simple text editor and are user-friendly for beginners. It is suggested to use nano to work fast and edit text files. The vi and jed are used for scripting and programming purposes.
Syntax for nano is:
nano [options] [file]
Syntax for vi is:
vi filename
Syntax for jed is:
jed filename
Other Options with the nano command:
Ctrl+O (save), Ctrl+X (exit), Ctrl+G (go to line), Ctrl+W (search)
22. vim command
The vim command stands for Vi IMproved. It is a powerful text editor with extensive features and a steep learning curve. A vim interface offers three modes, namely Normal (commands), Insert (text entry), Visual (text selection).
Syntax for vim command:
vim [options] [file]
Other Options with the vim command:
There are numerous commands and options; common ones include:
- :w – used for saving
- :q – used for quitting
- :wq – used for saving and quitting
- i – used for insert mode
- Esc – used for normal mode
- :q! – used to quit without saving
23. tee command
The tee command is a powerful Linux command for manipulating data streams. It allows you to duplicate the output of a command to both a file and the standard output simultaneously, making it incredibly useful for various tasks.
Syntax for tee command:
command | tee [-a] file1 [file2…]
24. awk command
The awk command is used to filter, format, and manipulate text data. Awk is a general-purpose scripting language used for a various tasks, including data mining, report generation, and more. Awk allows the user to use variables, numeric functions, string functions, and logical operators.
Using the awk command, one can perform mathematical operations, apply conditional statements (using if), loop with for & while, output expressions such as print and delete commands. It also contains the $n notation, a field in the current file line.
Syntax for awk command:
awk ‘pattern { action }’ [file]
25. sed command
A sed stands for Stream EDitor. A sed command is used to perform text manipulation and substitution. It helps in operations like selecting the text, substituting text, modifying an original file, adding lines to the text, or deleting lines without using a text editor.
Syntax for sed command:
sed [options] ‘s/old/new/’ [file]
Other Options with the sed command:
- d: used to delete lines
- p: used to print lines
- s/pattern/replacement/: used to substitute
26. locate command
Using a locate command, you can quickly find files and directories by name within a database.
Syntax for locate command:
locate [options]
27. cut command
The cut command is a Linux command-line utility that extracts sections of a selected file and prints the result to standard output. This command cuts parts of a line by field, delimiter, byte position, and character.
Syntax for cut command:
cut [options] [file]
Other Options with the cut command:
- -d: for specifying a delimiter
- -f: for selecting fields.
- -b: option specifies the byte positions to cut.
- -c: option specifies the character positions to cut.
Some examples of how to use the cut command:
1. To extract the first and third fields of a file:
cut -d, -f1,3 file.txt
2. To remove leading whitespace from a line:
cut -b 2- file.txt
28. sort command
The sort command is used to sort lines of text alphabetically or numerically. It prints lines of input text files in an arranged and specified order(sorted manner).
Syntax for sort command:
sort [options] [file]
Other Options with the sort command:
- -n: option can be used for numerical sorting
- -r: option can be used for reversing the order
- -k: option can be used for sorting by specific field
Some examples of how to use the sort command:
1. Sorting a file in descending order:
sort -r file.txt
2. Sorting file specifying column:
sort -k2 file.txt
3. Sort a file numerically:
sort -n file.txt
User and Permission Management Linux Commands
Below are several Linux commands for managing the system’s users and permissions.
29. sudo command
A sudo command permits you to run commands with the privileges of another user (Run a command with root privileges).
Syntax for sudo command:
sudo [command]
Other Options with the sudo command:
There are no specific options, but they are combined with the command to be executed.
The root password will be requested by Terminal when you execute a sudo command. You can also run the sudo command using useradd. Here is the syntax for that:
sudo useradd username
Caution! Using sudo access to run a command will change all the settings on your system. Be careful when executing this command, as misusing it can damage your system and do so only if you understand the possible consequences.
30. chmod command
A chmod command is used to assign the permissions to a file or directory. Using this Linux command, one can allocate control over a file, such as who can read, write, or execute a file.
Syntax for chmod command:
chmod <options> <mode> <file>
31. su command
The su command, short for substitute user, enables users to switch to another user account. It is often used to switch to the root account with administrative privileges.
Syntax for su command:
su [options] [user]
Other Options with the su command:
- -: to start a login shell after switching.
- -l: login as the target user
Use the “whoami” command to view the user account for the current shell.
32. uname command
The uname command is used to prints basic information about the operating system name and system hardware. It is commonly used to determine the processor architecture.
Syntax for uname command:
uname [option]
Other Options with the uname command:
- -a: Prints all available information about the system.
- -m: Prints the processor type.
- -n: Prints the system name (hostname).
- -r: Prints the kernel release.
- -s: Prints the kernel name.
- -v: Prints the kernel version.
To use the uname command, simply type uname in a terminal window. You can also use the uname command with one or more options listed above to get more specific information about the system.
33. chown command
The chown command, short for “change owner,”. It is a powerful Linux command that allows users to change the owner of files and directories. This command is commonly helpful in scenarios where administrators need to grant or revoke access to specific resources.
Syntax for chown command:
chown [option]… <owner>:<group> <file>
34. useradd,userdel
A useradd command is used to create user accounts and configure primary settings. The essential use of the “useradd” command is too simple: A user can be added just by providing their username.
E.g. to add a user called “ashu”, type the following command:
useradd ashu
Once the above command is executed, a new user account with the “ashu” name will be created. This user will have a home directory created under /home/ashu, and assigned with the primary group.
userdel command
A userdel command is used to delete user accounts & other related files. To delete a user account, just type the command as follows:
userdel username
E.g. to delete the created user account “ashu”, type command as mentioned below:
userdel ashu
35. passwd command
The passwd command is used to change your password.
Syntax for passwd command:
passwd
Other Options with the passwd command:
There are no specific options.
36. groups command
The group command is used to shows the groups you belong to.
Syntax for groups command:
groups [user]
Other Options with the groups command:
There are no specific options.
37. top command
A top command allows you to display and update sorted information about processes. In simple terms, it monitors running processes and system resource usage (CPU, memory, etc.) in real-time.
Syntax for top command:
top
Other Options with the top command:
- -c, –command: Displays the command line for each process.
- -u, –user=USERNAME: Displays only the processes owned by the specified user.
- -p, –pid=PID: Displays only the specified process.
38. free command
The free command is used to display the amount of free and used memory in the system(RAM and swap).
Syntax for free command:
free
Other Options with the free command:
- -k: This option displays the output in kilobytes.
- -m: This option displays the output in megabytes.
- -g: This option displays the output in gigabytes.
- -t: This option displays the total memory.
- -s: This option displays the output in a single column.
39. df command
The df command is used to show the information about disk space usage on mounted file systems in percentage and kilobyte (KB).
Syntax for df command:
df [options] [file|directory]
Other Options with the df command:
- -h: human-readable output.
- -T: show file system types.
- -m – show information on the file system used in megabytes (MB).
- -k – outputs file system used in kilobyte (KB).
40. ps command
The ps command is used to show running processes.
Suppose you execute the ps command without an option or argument. In that case, the shell will report the processes that are currently executing along with the following details, such as unique process ID(PID), The terminal’s type (TTY), Duration of operation (TIME) and the command (CMD) that starts the procedure.
Syntax for ps command:
ps [options]
Other Options with the ps command:
- -a: option shows all processes.
- -u: option displays user-owned processes.
- -x: option displays processes without controlling terminals.
41. kill command
The kill command permits you to terminate a running process. It sends a signal to a process, often terminating it using its identification number (PID). To get the PID, run the following command:
ps ux
Syntax for kill command:
kill [options] [PID]
To terminate a program, there are 64 signals available. On this, SIGTERM and SIGKILL are the most common. SIGTERM is the default signal that allows the program to save its progress before quitting. SIGKILL now forces systems to abort and discard unsaved progress.
Other Options with the kill command:
- –s: option is used to specify the signal name.
- -n: option is used to specify the signal name
- -l: option lists the signal names
The most often used signals are as follows:
- 1 (SIGHUP) – Terminates the operation.
- 9 (SIGKILL) – Ends the process unconditionally.
- 15 (SIGTERM) – Stops an active process.
42. reboot command
The reboot command is utilised to restart the system. It is similar to the shutdown command, but it does not provide any options for scheduling or extending the timing of the notification.
Syntax for reboot command:
reboot
43. du command
The du command stands for “disk usage”. It is a Linux command that calculates file and directory size. It is a very useful command for managing disk space.
Syntax for du command:
du [option] [file|directory]
44. htop command
The htop command is the advanced version of the “top” command. It provides a user-friendly interface for monitoring your system’s performance.
Syntax for htop command:
htop [options]
Other Options with the htop command:
- -d – displays the delay between updates in tenths of seconds.
- -C – allows monochrome mode.
- -h – reveals the help message and exits.
45. hostname command
The hostname command is used to print or set the system’s hostname.
Syntax for hostname command:
hostname [HOSTNAME]
Other Options with the hostname command:
- -f: Print the fully qualified domain name (FQDN).
- -i: Print all network addresses for the host.
46. time command
The time command helps to measure the execution time of a command or script.
Syntax for time command:
time [COMMAND]
The result displays elapsed real time, user CPU time, and system CPU time.
47. systemctl command
The systemctl command is a tool used to manage and control systemd services and units. Systemd is a system and service manager in Linux that launches services.
Syntax for systemctl command:
systemctl [commandname] [service_name]
The common actions performed using the systemctl command is to start, stop, restart, enable, disable, mask, unmask, and reload services.
48. watch command
The watch command lets the user execute a command repeatedly, displaying its output in real-time.
Syntax for watch command:
watch [option] command
49. jobs command
The jobs command lists the currently running background jobs in the shell. It can help list all jobs, running, stopped, or completed jobs.
Syntax for jobs command:
jobs [options] jobID
50. whoami command
A whoami command is used to print the current user’s username.
Syntax for whoami command:
whoami [option]
51. id command
The id command is used to display your user ID and group ID.
Syntax for id command:
id [user]
52. shutdown command
The shutdown Linux command lets you shut down, restart, or put your system to sleep. It can also be used to end a user session.
Syntax for shutdown command:
shutdown [option] [time]
Other Options with the shutdown command:
- shutdown now: Option allows your system to shut down and power off immediately
- shutdown -h now: Similar to the option “shutdown now”. Explicitly mention halt. For halt, all modern systems power off the system.
- shutdown -h <time>: Indicates the desired shutdown (power down) time.
- shutdown -P: This option works like the -h option on most contemporary systems. Switch off the system’s power.
- shutdown -c: Terminates a planned shutdown.
- shutdown -r: This causes a one-minute system reboot.
- shutdown -r <time>: command restarts the computer at the given time.
- Shutdown -r now: Quickly restarts the computer.
Network Management and Troubleshooting Linux Commands
Here are commonly used Linux commands for managing and troubleshooting network connections.
53. ping command
A ping command allows you to test network connectivity to a host by sending ICMP echo requests. This can also assist you in determining packet loss and troubleshooting communication difficulties.
The following are the main functions of the ping command:
- Verify the status of the server.
- Determine DNS problems.
- Verify the Internet and LAN connections as well as network connectivity.
Syntax for ping command:
ping hostname or ping IP_address
Other Options with the ping command:
- -c: option indicates how many packets to deliver before the command is terminated.
- -i: Defines the time between packet sends.
- -s: Indicates the ICMP packet size in bytes.
- -t: Modifies the packets’ Time-to-Live (TTL) value.
- -q: Shows a summary and suppresses most of the output.
- -W: Defines the wait time in seconds for a response.
- -v: Makes the output more verbose.
- -A: A loud ping. This option provides an audio indication of successful pings by producing a sound for each successful answer.
- -I: Indicates the IP address to use as the source for sending ping packets.
54. traceroute command
A traceroute command attempts to trace the route taken by packets (IP) when they move from one host to another over a network. It provides you with trip time and router-associated information.
Syntax for traceroute command:
traceroute hostname or traceroute IP_address
Other Options with the traceroute command:
For more thorough packet monitoring, include the following options:
- -m: option supplies each packet’s maximum hops.
- -n: stops the command from resolving IP addresses to hostnames for quicker tracing.
- -I: modifies the default UDP packets to UCMP.
- -w: adds a timeout in seconds.
55. netstat command
The netstat command displays network status, routing tables, interface statistics, masquerade connections, and more. This Linux command can also be used as a monitoring tool for checking the network connections.
Syntax for netstat command:
netstat [options]
Other Options with the netstat command:
- -a: option to display all sockets.
- -t: option to display TCP sockets.
- -u: option to display UDP sockets.
56. ifconfig command
The ifconfig command is a network configuration tool to configure network interfaces, set IP addresses, and manage network connections.
Syntax for ifconfig command:
ifconfig [interface] [option]
Other Options with the ifconfig command:
- up: Carry an interface up.
- down: Carry an interface down.
- add: add an IP address.
57. route command
The route command is used to view and manipulate the IP routing table. A route command is a powerful Linux command which allows you to view, add, or delete entries in the routing table, determining the path that network traffic will take.
Syntax for with route command:
route [option]
Other Options with the route command:
- -n: for displaying the routing table
- -d: too delete a route
58. wget
The goal of the wget command is to download files from the web.
Syntax for with wget command:
wget [OPTIONS] URL
59. curl
A curl command in Linux is meant to transfer data to/from servers, with more features than wget.
Syntax for with curl command:
curl [OPTIONS] URL
Other Options with the curl command:
- -o: Specify output filename.
- -X: Specify HTTP method (GET, POST, etc.).
- -L: Follow redirects.
- -u: Provide username and password for authentication.
60. scp
Using SSH, the scp command is used to transfer data securely between hosts.
Syntax for with scp command:
scp [OPTIONS] SOURCE DESTINATION
Other Options with the scp command:
- -r: Recursively copy directories.
- -P: Specify SSH port.
- -i: Specify identity file for authentication.
61. rsync
To effectively synchronize files and directories between hosts, use the rsyns command.
Syntax for with rsync command:
rsync [OPTIONS] SOURCE DESTINATION
Other Options with the rsync command:
- -a: Archive mode (preserve permissions, ownership, etc.).
- -v: Verbose output.
- -z: Compress data during transfer.
- -e: Specify remote shell to use (e.g., ssh).
62. nslookup
In order to resolve hostnames and IP addresses, DNS servers are consulted using the nslookup command.
Syntax for with nslookup command:
nslookup [OPTIONS] HOSTNAME
Other Options with the nslookup command:
- -type=TYPE: Specify query type (e.g., A, MX, NS).
- -server=SERVER: Use a specific DNS server.
63. dig
A dig command is used to flexible the DNS lookup tool with more options than nslookup.
Syntax for with dig command:
dig [OPTIONS] @SERVER HOSTNAME
Other Options with the dig command:
- +short: Display only the answer section.
- +trace: Trace the DNS query path.
- +noall: Suppress most output except the answer section.
File Compression Linux Commands
Below are the commonly used Linux commands for file compression purposes.
64. gzip Command:
A gzip command compresses files using the Lempel-Ziv (LZ77) algorithm—typical Use Cases: General-purpose compression, saving disk space, and archiving files. The file extension will be .gz.
Syntax for with gzip command:
gzip [option]… file…
Other Options with the gzip command:
- -d: Decompress (equivalent to gunzip).
- -c: Write output to standard output.
- -r: Recurse into directories.
- -v: Verbose output.
- -9: Maximum compression level.
65. gunzip:
A gunzip is used for decompressing gzip-compressed files.
Syntax for with gunzip command:
gunzip [option]… file…
Other Options with the gunzip command:
- -c: Write output to standard output.
- -f: Force decompression even if the file has multiple links.
- -v: Verbose output.
66. zip:
Purpose: Compresses files into a single archive using various algorithms (often DEFLATE). Typical Use Cases: Cross-platform compatibility, creating self-extracting archives. The file extension is .zip.
Syntax for with zip command:
zip [option]… zipfile file…
Other Options with the zip command:
- -r: Recurse into directories.
- -j: Store only the file name, not the full path.
- –q: Quiet mode (no output).
- -P: Set a password for the archive.
67. unzip:
A unzip command is used to decompresses zip archives.
Syntax for with unzip command:
unzip [option]… zipfile
Other Options with the unzip command:
- -l: List archive contents.
- -d: Extract files to a specific directory.
- -o: Overwrite existing files without prompting.
- -j: Junk paths (extract only the file names).
Package Managers Linux Commands
Below are the commonly used Linux commands for package management purposes.
68. apt-get command:
The purpose of an apt-get Linux command is to be a main package manager for Debian and Ubuntu distributions.
Syntax for apt-get command:
apt-get [COMMAND] PACKAGE_NAME…
Common apt-get Commands:
- install: Install packages.
- remove: Remove packages.
- update: Update package lists.
- upgrade: Upgrade installed packages.
- search: Search for packages.
- autoremove: Remove unused packages.
69. yum command:
The purpose of the yum Linux command is to manage Package for Red Hat and CentOS distributions.
Syntax for yum command:
yum [COMMAND] PACKAGE_NAME…
Common yum Commands:
- install: Install packages.
- remove: Remove packages.
- update: Update package lists.
- upgrade: Upgrade installed packages.
- search: Search for packages.
- clean: Clean up cached package files.
70. pacman (Arch Linux):
The main purpose of the Pacman Linux command is to roll out the release package manager for Arch Linux.
Syntax for pacman command:
pacman [COMMAND] PACKAGE_NAME…
Common pacman Commands:
- -S: Install packages.
- -R: Remove packages.
- -Syu: Update and upgrade all packages.
- -Qs: Search for packages.
- -Sy: Download packages without installing.
Shell Utilities Linux Commands:
This section will examine basic Linux commands for Shell Utilities management.
71. alias command:
An alias command is used to create shortcuts for frequently used commands.
Syntax for alias command:
alias SHORTCUT=”COMMAND”
Example: alias ll=”ls -l” creates “ll” as a shortcut for “ls -l”.
The main benefits of the “alias” Linux command are that it saves time and improves command-line efficiency.
72. history command:
A history command is used to display a list of previously executed commands. One can quickly review past commands, troubleshoot errors, and reuse commands with the history command.
Syntax for history command:
history
Other Options with the history command:
- -c: Clear the history.
- -n: Show only the last n commands.
- -i: Edit a specific command from the history.
73. man command:
The purpose of the man Linux command is to access manual pages for shell commands and libraries. The main benefit of man command is to learn detailed information about commands, options, and syntax.
Syntax for man command:
man COMMAND
Linux Commands for Searching File and Command Locations
There are Linux commands, such as “whereis”, “which” are available for locating files and commands in the Linux system. Let’s learn more about these Linux commands as they share some similarities while they serve distinct purposes:
74. whereis command:
A whereis is a Linux command used to quickly find files by name using a pre-built database. It also quickly searches for the location of files related to a command (executable, source code, manual page).
Syntax for whereis command:
whereis COMMAND
75. which command:
Using a which command, you can quickly locate the path of a given command and, with this, find the exact path of an executable command from your system’s search path.
Syntax for which command:
which COMMAND
Tips and Tricks – Linux Commands
Below are some quick tips and shortcuts to make your Linux command-line experience smoother and more efficient:
- –help: Use with any command to get a detailed usage guide.
- exit: Use to close the terminal.
- clear: Use to clean the Terminal screen.
- tab: Use to autofill after entering a command with an argument.
- ctrl+c: Use Ctrl + C to terminate a running command.
- ctrl+z: Use Ctrl + Z to pause a working command.
- ctrl+a: Use to quickly position your cursor at the start of the current line.
- ctrl+e: Use to efficiently move the cursor to the end of the line.
- ; or &&: Use to separate multiple commands
- –version: Display version information.
Conclusion:
Gone are the days of clunky GUIs limiting our system interactions. Linux commands empower us with a robust, flexible way to control and enhance our VPS & Dedicated Server experience. They unlock hidden features, automate tasks, and provide granular control over every aspect of our virtual server.
This guide has served as your gateway to this invaluable world, highlighting over 75 essential Linux commands. We’ve explored how they’re built – with their command names, flags, and arguments – and dived into various categories:
- File Management Linux commands: Navigate your directories with finesse using ls, cd, mkdir, and more. Edit text files with precision using nano, sed, and awk.
- System Administration Linux commands: Monitor performance with uptime, free, and top. Manage users and permissions with chmod, chown, and useradd.
- Networking Linux commands: Stay connected with ping, traceroute, and netstat. Transfer files effortlessly with scp and rsync.
- Package Management Linux commands: Install and update software seamlessly with apt-get, yum, or pacman.
- Searching and Locating Linux commands: Find what you need instantly with locate, which, and whereis.
- Miscellaneous Tools Linux commands: Automate tasks with watch, create shortcuts with alias, and explore further with man.
Remember, mastering these Linux commands isn’t just about efficiency; it’s about unlocking the full potential of your VPS & Dedicated Servers. Whether you use a Terminal or an SSH client, these Linux commands are your key to aspects for efficiently managing your VPS & Server experience. So, dive deeper, experiment, and unlock the true power of Linux!
Kirti S