Hello there!! đ»
If you are searching for mostly commonly used Linux commands as a beginner to linux, then you are at a right place. Before diving into main section, please make a note that Linux is case sensitive because âdocâ and âDocâ are different as far as the OS is concerned.
- echo â{my string}â : This command prints the string that is passed as an argument.
root@192.168.0.28:~#echo âHello Worldâ
Hello World
2. whoami : It outputs the username of the currently logged-in user.
3. hostname : It prints the systemâs host name and also you can view the IP address of the system by passing -i argument as hostname -i .
4. pwd : This command stands for print working directory. As the name suggests, it outputs your current working directory.
5. ls -l : Lists all the files and directory present in your current working directory in long format i,e along with the permissions, date, time and size.
- ls -ltr : lists all files and directories with modification time ( to newest) in reverse order
- ls <directory_name> : lists all the contents of a directory without having to navigate to it.
- ls -a : lists all the files and directories including hidden files
6. mkdir {directory_name}: This allows you to create a new directory.
root@192.168.0.28:~#mkdir mydirectory
7. cd {directory_name} : cd stands for change directory. Its allows you to change the directory. Here {directory_name} refers to the target directory which you want to navigate from current working directory.
root@192.168.0.28:~# cd mydirectory
root@192.168.0.28:~/mydirectory
- cd {directory}/{sub_directory}: This helps you to directly navigate into a directory present inside another directory (commonly referred as subdirectory).
root@192.168.0.28:~# cd mydirectory/directory2
root@192.168.0.28:~/mydirectory/directory2
8. touch {file_name} : To create an empty file.
root@192.168.0.28:~#touch emptyfile
9. nano {file_name} : To create a new file by adding the contents.
root@192.168.0.28:~#nano myfile
10. vi {file_name} : vi (vim ) is the one of the advanced editors that is used in linux.
root@192.168.0.28:~#vi myanotherfile
11. cat {filename} : This commands prints the content of the file.
root@192.168.0.28:~#cat myfile
Hi! This is a demo file
- cat > {filename} : It allows to overwrite the content in the target file.
- cat >> {filename} : With the help of this command, strings can appended to the existing content in the file.
cat /{directory_name}/{file_name} : This outputs the contents of a file within directories without having to navigate to it.
echo ânewly added textâ >> {filename} will also works for this scenario.
12. find -name {filename} : To search for files or directory.
root@192.168.0.28:~#find -name myfile
./myfile
You can also search for more than one file using wildcard patterns. For example, if you want retrieve all the files that has the string âmydocâ in its filename, try with this command : â find -name *mydoc* â .
13. grep âmystringâ {filename} : grep stands for global regular expression print. This command allows us to search for a string in file or searching a keyword in any command output.
root@192.168.0.28:~#grep "second" myfile
second line in my file
root@192.168.0.28:~#ls -l | grep myfile
drwxr-xr-x 3 root root 4096 Dec 18 12:14 myfile
Pipe operator | : It is used to merge commands in linux where the output of first command serves as input to second command.
grep -i âmystringâ {filename} : To Ignore case distinctions in characters while searching in the file.
14. rm {filename} : To delete the specified file.
root@192.168.0.28:~#rm file2
- rm -f {filename} : This will ignore nonexistent files and arguments, never prompt.
- rm -d {directory} : To remove an empty directory.
- rm -r {directory} : To remove non-empty directories and the files within them recursively.
A file deleted with the rm command is deleted permanently, not moved to any trash folder.
15. adduser {username} : To create a user.
root@192.168.0.28:~#adduser rach
Adding user `ram' ...
Adding new group `ram' (1016) ...
Adding new user `ram' (1014) with group `ram' ...
Creating home directory `/home/ram' ...
Copying files from `/etc/skel' ...
New password:********
Retype new password:********
passwd: password updated successfully
Changing the user information for ram
You can also use the command âuseradd <username>â to create user, but adduser is more secure than useradd, as it prompts you to set the password in the initial user creation process itself and also sets up user folders, directories, and other necessary functions easily.
userdel <username> : To delete the specified user.
root@192.168.0.28:~#userdel rach
16. id {username} : It prints the userid and groupid of the user.
root@192.168.0.28:~#id rach
uid=1018(rach) gid=1018(rach) groups=1018(rach)
17. cp {myfile} {copied_myfile} : Copy command (cp) is used to copy a file or directory.
root@192.168.0.28:~#cp file2 newfile
18. mv {file_name} {destination} : Move (mv)command helps you to move a file from one path to another specified path.
mv command also used to rename a file : âmv {myfile} {myrenamedfile}â .
root@192.168.0.28:~#mv file2 file8
19. alias {shortcut}={command}: This feature allows you to create your own shortcut replacing the original linux command. For example, if I want to use the word ârachâ instead of going with âls -lâ for viewing list of files in long format.
root@192.168.0.28:~#alias rach=ls-l
root@192.168.0.28:~#rach
total 8
-rw-r--r-- 1 root root 0 Jan 17 17:45 file
-rwxrwxrw- 1 root root 0 Jan 17 17:46 file2
drwxr-xr-x 2 root root 4096 Jan 17 17:46 mydirectory
-rw-r--r-- 1 root root 21 Jan 17 17:46 myfile
20. man {command} : It provides us the user manual for all linux commands which includes command description, options, examples and other information about the command.
We can also get information about the built-in shell commands with the use of help command. For example, if you want to know more about mkdir command --> mkdir --help
Happy Learning!! đ