Linux commands that every Linux System Administrator should know with examples – Part-1

If you are looking for Linux Commands from beginner to moderate & advance level, you have landed in the right place and website. This is not a complete and comprehensive list of commands. However, this can be helpful to kick-start of Linux commands and you might want to bookmark it for future reference. There are some commands which requires root (superuser) credentials and some are available for everyone. All the binaries are available on below location by default. 

/bin – The command available under /bin directory can be executed by everyone.
/sbin – However, to execute /sbin directory command need special permission or root credential.  
/usr/bin – General system-wide binaries.
/usr/sbin -Binaries with superuser (root) privileges required.

In this series of tutorials, we will try to cover all Linux Commands which are useful in daily system operations.

Read Also: 10 – top command in Linux with examples.
Read Also: 11 – Essential Linux Commands For Network Configuration and Troubleshooting
Read Also: TAR Command in Linux
Read Also: sysstat – Linux System Performance Monitoring and Usage Tool
1. ls command examples:
ls is the very first command and frequently used command which list files and directory contents available on location.
Syntax:
ls [option] [file]
$ ls

ls without option shows directory contents on current directory. 
Note: 

. Directories are shown in blue color.
. Files are shown in white.
. You may find similar color schemes in other Linux distros.

$ ls -al
This will long list and shows hidden files also.

Also Read: Linux Commands That Every Linux System Administrator Should Know with Examples Part-2
Note: Type man ls [from Linux console] for more ls command options.
2. tar command examples:
Create a tar archive.
Syntax:
tar [option] [archive-file-name] [file-or-directory-to-archive]
# tar -cvf dir1.tar dir1/

Extract from existing tar archive, this will extract dir1.tar archive in /tmp directory.
tar -xvf dir1.tar -C /tmp/

Note: Type man tar [from command prompt] for more tar command options.

3. pwd command example
pwd command is to shows present or print current working directory.
Syntax:
pwd [OPTION]
# pwd
4. cd command example
cd stands for Change Directory is a command to toggle between directories.
Syntax:
cd [directory]
# cd dir1

5. cat command example
One of the most frequently used command. cat is a short form of ‘concatenate’ and allow users to create file, list contents of a file, redirect file output etc.
Syntax:
cat [option][file]
$ cat > test.txt
$ cat test.txt

In the above screenshot we are creating test.txt file, awaits from user to input. “CTRL+D” to exit and contents will be saved on test.txt file. You may see the content of the file with cat command.
6. less command
less is useful command to displays large file contents in one page at a time in your terminal.
Syntax:
less [filename]
$ less test.txt
7. mkdir command
mkdir command helps user to create a directories. Creates directory called dir1 with below command.
Syntax:
mkdir [directory-name]
$ mkdir dir1
8. cp command example
cp command copy files and directories one place to other. While copying directory including it’s files and sub-directories use the -r option. Following command copy dir1 directory and it’s contents to destination testdir.
Syntax:
cp [option] [source][destination]
$ cp -r dir1/ tmpdir/

9. mv command example
mv stands for move is used to rename files and directories and move files and directory to different directory.
Syntax:
mv [option] [source] [destination]
# mv mv.txt mv_new.txt
# mv mv_new.txt /tmp
Above mv command rename mv.txt file as mv_new.txt and move renamed file mv_new.txt to /tmp directory.
10. rm command example

rm stands for remove is used to remove or delete files and directories.

Syntax:
rm [option] … FILE…
# rm -i test.txt
# rm rm_dir
# rm -rf rm_dir

. -i (Interactive deletion) -i option with rm command ask the user for confirmation before removing each file.
. -r recursively remove files and directory. 
. -f forcefully remove

Note: Cross check before removing any files and directories.

11. touch command example
touch command is used to create, change and modify timestamps of a file. This will create an empty file.
Syntax:
touch [filename]
# touch teclues.txt
# touch teclues1.txt teclues2.txt teclues3.txt

Above command creates teclues.txt and also can create multiple files as shown above.

12. clear command
clear command is to clear terminal screen. This command is also available on Unix and other Unix-like operating system.
Syntax:
$ clear
13. df command example
df (disk free) command shows the disk free space in human readable format, filesystem types, and filesystem mounted on.
Syntax:
df [OPTION]… [FILE]…
$ df -h

-h (–human-readable)
14. du command example
du is short form of disk usage command shows disk usage by files and directories.
Syntax:
du [option] [file-name] [directory-name]
$ du -sh test.img
du -sh dir2

. -s option  –summarize
. -h option –human-readable
15. find command example
find is also a one of the most frequently used command to search for a file and directory on your file system based on expression you specify.
Syntax:
find [option] [starting/path] [expression]
$ find . -name data.txt

16. grep command example
grep (stands for Global Regular Expression Print) command is used to search text or searches the given file for lines containing a match to the given strings or words.

Syntax:
grep [OPTIONS] PATTERN [FILE…]
$ grep teclues /etc/passwd


17. echo command example
echo command to display line of string/text in STDOUT that are being passed as an argument.
Syntax:
echo [option] [string]
$ echo “Hello teclues.com”

18. wc command example
wc stands for Word Count, As the name suggest is is used to count Newline Count, Word Count & Byte Count in the files specified in the arguments.
Syntax:
wc [option]…[file]…
$ ls -l | wc -l
Output

Above output shows number of lines along with ls -l command.
19. history command example
If you want to see the command executed in the past in Linux , history command shows the the commands that you have entered in the past.
Syntax:
history
$ history

20. w command example
w command shows information about users currently logged in and what they are doing currently on the system. Also shows the load average of the system.
Syntax:
w [options] [user]
$ w

21. who command example
who command shows information about users currently logged in on the system. Also shows the following information.
1. Date and Time of last system booted.
2. Number of users logged in
3. Current run level of the system

Syntax:
w [options] [user]
$ who
$ who -bH
$ who -a

22. free command example

free command line utility to show the total, used and free momory also displays total swap memory, free and used by the system.
Syntax:
free [option]


Output show in MB with option -m 

23. whoami command example
whoami is the concatenation of the words “Who am I“? whoami command is available on Linux, Unix-like, Windows Operating System. It displays username of the current user logged in.
Syntax:
whoami [OPTION]
$ whoami
24. su command example
su stands for Switch User, is used to switch to another user on same session.
Syntax:
su [options] [-] [user [argument…]]
$ su helen

 

 

Output shows that teclues user is switching to helen user, but he/she has to have password of user of which he/she switching over.
Also Read: Linux Commands That Every Linux System Administrator Should Know With Examples Part-4
25. date command example

date command displays system date and time also can set data and time of the system. Note: You need root or super user access to set date and time.
Syntax:
date [OPTION]… [+FORMAT]


26. timedatectl command example

timedatectl control system time and data in Linux. It allows to query and change system clock and it’s settings also shows the followings:
1. System current date and time.
2. NTP Status
3. TZ (timezone)
Syntax:
timedatectl [OPTIONS…] {COMMAND}
timedatectl 

27. hostnamectl command example
hostnamectl is used to query and change the system hostname and related settings. Note: You need root or super user access to change hostname.
Syntax:
hostnamectl [OPTIONS…] {COMMAND}
hostnamectl 
# hostnamectl set-hostname teclues –static


28. locate command example
locate command to find the files by it’s name and search faster then find command. Becasue locate command search files in database instead of searching in filesystem. Database contains bits and parts of files and their related paths on system.
Syntax:
locate [option]… [pattern]…
$ locate  test.img

While executing locate command, you may encountered error as “locate: can not stat () `/var/lib/mlocate/mlocate.db’: No such file or directory”. In this case, update locate database with updatedb command as shown above.
29. head command example
head command is a contrary to tail it shows beginning of a file. By default it prints first 10 lines of the file to standard output.
Syntax:
head [OPTION]… [FILE]…

$ head /etc/passwd
30. tail command example
tail command prints last 10 lines by default of a file.
Syntax:
tail [OPTION]… [FILE]…
# tail /var/log/messages 


Conclusion: In this first series of Linux commands, we have covered 30 Linux commands. We will be covering series of commands in the upcoming articles. Big thanks for reading all the way to the end. Please share it with Your Friends & Help Someone… and also Like Our Facebook Page. Let me hear your thoughts in the comments below!

Leave a Comment