Linux users can’t just live with the GUI, CLI usage makes the work more efficient and fast. Hence I have brought together a set of 15 commands which are very useful for your daily works in Linux.
This command displays the current path where the terminal is situated.
|pwd||Gives the path of the current working directory|
This command displays all the files in the current directory.
|ls path||Lists all the files in the path given; if no path is given, then lists all files in the current directory|
|ls -l||Lists all the files with all the permissions attached and timestamps (long format)|
|ls -a||Lists all the files + the hidden files (dotfiles)|
|ls *.jpg||Lists all the jpg files in the current directory|
ls can be used for a lot more things. To know more about it, you can use the command: man ls
The echo command is widely used in bash and shell scripts to output text to a screen or a file.
|echo Any text you want||Prints any text you want|
|echo “Any text you want”||Prints any text you want using quotations|
Echo can be used with or without the quotes though usage of double quotes will be useful when working with large text or escaping some special characters in Linux.
Cat command is frequently used in Linux; it reads the input from the file and gives the output to the screen. Cat command can also be used to create and concatenate files.
|cat filename||Reads the given file|
|cat > filename||Creates new files|
cat can be used to create files using the redirection operator (>). Just type cat > filename you want and enter the text you want to input into the file, and press Ctrl+D to end the terminal input.
The touch command is another command used to create files in Linux.
|touch filename||Creates a single file|
|touch filename1 filename2 filename3||Creates multiple files|
Rm command is used to delete any file or directory.
|rm filename||Deletes the given file|
|rm *.txt||Deletes all files with .txt extension|
|rm -i filename||Will ask before deleting the file|
|rm -r directory||Will delete recursively , used to delete directories|
Cd command is used to change the current working directory in Linux.
|cd||move to users home directory from anywhere|
|cd ..||move one step back|
|cd path||change to the path given|
- ►Mv command is used to move one or more files or directories from one location to another location.
- ►It can also be used to rename a file or a directory.
|mv source destination||Moves a file from sorce location to destination|
In the above example, I have moved the file testing in Desktop to Downloads and used ls and grep to check if it’s moved.
Grep command is an excellent CLI utility used to search for text in a file or can also be used to locate files in a directory. Learning to use grep and regular expressions will simplify lots of work for sysadmins.
|grep “word” filename||Searches for a word given in the given filename|
|grep -c “word” filename||Gives the count of matches of the word in the given file|
|grep -i “word” filename||Searches for a word shown in the given file ignoring the case sensitivity|
In the above example, I have moved the directory testing in Desktop to Downloads and used ls and grep to check if it’s moved.
- ►Find command is an excellent CLI utility used to search and locate files based on a set of conditions you specify.
- ►Find can be used in various situations like file size, permissions, date, etc.
|find . -name filename.txt||Searches for the given filename in the current directory|
|find ~/Desktop -name filename.txt||Searches for the given filename in Desktop|
|find ~/Downloads -type f -name “*.php”||Searches for all php files in Downloads dir|
|find ~/Desktop -type f -empty||Find all empty files in Desktop|
|find ~/Desktop -type d -empty||Find all empty directories in Desktop|
- ►Sudo command is widely used to obtain administrator or root privileges.
- ►For example, if you want to edit any system files which need root permissions, you can use the sudo command.
|sudo cat anyfile||Attaching sudo to any command will give root privileges|
|sudo -s||Runs the shell specified by SHELL Environment variable|
|sudo -l||Prints the allowed privileges for the current user|
Ping command is used to check the connection to a website, verifying if a website is up or down.
|ping ipaddress||Ping any ipaddress|
|ping www.example.com||Ping any website|
Receiving ICMP Packets = Up , Unreachable = Down
- ►zip command is a compression and file packaging utility for Linux. Zip is used to reduce the file size.
- ►You can add lots of files into a single zip and send it over the internet.
|zip filename_of_zip files_to_be_added_to_zip||Zips a file|
chmod command is used to grant permissions to a file or a directory. This command is exceptionally crucial for sysadmins. Giving permissions for different users and allowing them to access files according to policies is essential for every company to ensure security.
There are 3 different permissions i.e Read(r) , Write(w) and Execute(x).
|chmod +x numbers.py||Adds executable permission to a python file|
|chmod +r numbers.py||Adds readable permissions to a python file|
|chmod +w numbers.py||Adds writable permissions to a python file|
- chmod command can be combined with the find command to change permissions for directories and a lot more.
- To know more, use the command: man chmod .
The ps command is used to list currently running processes along with their PIDs.
|ps a||lists all processes of all the users|
|ps au||lists all the processes in a user-oriented format|
|ps aux||lists all the processes in user-oriented format and shows processes that are not started from the terminal.|
The most common usage of ps command is: ps ax | grep “The process you want.”
PID: Unique Process ID for each process
TTY: Name of controlling terminal for the process
CMD: The command which was used to start the process
TIME: CPU time of process shown in Minutes and seconds.
We have looked into 15 Important Commands needed for daily life in detail. I hope new Linux users who are intimidated by commands can now switch to CLI after reading this post. If you have any questions or feedback, feel free to leave a comment.
I also run a small youtube channel on some exciting topics, do look into it.