[tutorial] Top 20 Basic Linux Commands

1 message · started by Devi Garcia on Jul 29, 2020

[tutorial] Top 20 Basic Linux Commands

From Devi Garcia · Jul 29, 2020



Top 20 Basic Linux Commands

In this Tutorial, You Learn about Top 20 Basic Linux Commands from this tutorial. Linux is a family of open-source Unix-like operating systems based on the Linux kernel.


1. pwd command #

The pwd command writes the full pathname of the current working directory to the standard output.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ pwd
/mnt/techsolbox_dir
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
2. ls command #

The ls command supports showing a variety of information about files.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls
data1a  data2b  data3c  data5a       files10.txt  files2.txt  files4.txt  files6.txt  files8.txt
data1b  data2c  data4a  data5b       files1.pdf   files3.pdf  files5.pdf  files7.pdf  files9.pdf
data1c  data3a  data4b  data5c       files1.txt   files3.txt  files5.txt  files7.txt  files9.txt
data2a  data3b  data4c  files10.pdf  files2.pdf   files4.pdf  files6.pdf  files8.pdf
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
3. cd command #

The cd command is used to change the current directory.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ pwd
/mnt/techsolbox_dir
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ cd data2a/
techsolbox@redaakash-Akki /mnt/techsolbox_dir/data2a $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir/data2a $ pwd
/mnt/techsolbox_dir/data2a
techsolbox@redaakash-Akki /mnt/techsolbox_dir/data2a $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir/data2a $
4. cp command #

This cp command is used to copy files or group of files or directory.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls
data1a  data2b  data3c  data5a       files10.txt  files2.txt  files4.txt  files6.txt  files8.txt
data1b  data2c  data4a  data5b       files1.pdf   files3.pdf  files5.pdf  files7.pdf  files9.pdf
data1c  data3a  data4b  data5c       files1.txt   files3.txt  files5.txt  files7.txt  files9.txt
data2a  data3b  data4c  files10.pdf  files2.pdf   files4.pdf  files6.pdf  files8.pdf
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ cp files1.txt files2.pdf data1b/
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls data1b/
files1.txt  files2.pdf
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
5. cat command #

The cat command is one of the most frequently used commands in Linux/Unix like operating systems. cat command allows us to create single or multiple files, view contain a file, concatenate files, and redirect output in terminal or files.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ cat files1.txt 
TechSolBox is a leading Website Development company in Gurgaon. We offer Python, Linux development and Digital Marketing service to grow the business.
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
6. mv command #

mv is a Unix command that moves one or more files or directories from one place to another.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls files1.txt 
files1.txt
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls data2c/
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ mv files1.txt data2c/
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls file1.txt
ls: cannot access 'file1.txt': No such file or directory
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls data2c/
files1.txt
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
7. rm command #

rm is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls files4.pdf
files4.pdf
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ rm files4.pdf
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls files4.pdf
ls: cannot access 'files4.pdf': No such file or directory
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
8. rmdir command #

As the name suggests, the rmdir command is focused at removing directories, although empty-ones only. Following is its syntax:

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls -d data3c
data3c
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ rmdir data3c
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls -d data3c
ls: cannot access 'data3c': No such file or directory
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
9. mkdir command #

The mkdir command in the Unix, DOS, DR FlexOS, IBM OS/2, Microsoft Windows, and ReactOS operating systems is used to make a new directory.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls -d techsolbox
ls: cannot access 'techsolbox': No such file or directory
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ mkdir techsolbox
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls -d techsolbox
techsolbox
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
10. touch command #

touch is a basic Linux command to create empty files or change files timestamps (last date or time of file access or modification).

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls LinuxWorld.txt
ls: cannot access 'LinuxWorld.txt': No such file or directory
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ touch LinuxWorld.txt
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ls LinuxWorld.txt
LinuxWorld.txt
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
11. ln command #

ln command is used to create hard links and soft links for files in Linux. Let’s discuss all the three forms one by one.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ cat files3.txt 
TechSolBox is a leading Website Development company in Gurgaon. We offer Python, Linux development and Digital Marketing service to grow the business.
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ln -s $PWD/files3.txt $PWD/data1a/
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ echo $PWD
/mnt/techsolbox_dir
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ cat data1a/files3.txt 
TechSolBox is a leading Website Development company in Gurgaon. We offer Python, Linux development and Digital Marketing service to grow the business.
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ echo "New Data" >> data1a/files3.txt 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ cat files3.txt 
TechSolBox is a leading Website Development company in Gurgaon. We offer Python, Linux development and Digital Marketing service to grow the business.
New Data
techsolbox@redaakash-Akki /mnt/techsolbox_dir $
12. head command #

The head command is a command-line utility for outputting the first part of files given to it via standard input.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ cat files3.txt 
TechSolBox is a leading Website Development company in Gurgaon. We offer Python, Linux development and Digital Marketing service to grow the business.
New Data
Hello User
Hello User from TechSolBox
Linux is an open-source kernel.
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ head -n 2 files3.txt 
TechSolBox is a leading Website Development company in Gurgaon. We offer Python, Linux development and Digital Marketing service to grow the business.
New Data
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
13. sudo command #

The Sudo command allows you to run programs as another user, by default the root user. If you spend a lot of time on the command line, sudo is one of the commands that you will use quite frequently.

user@redaakash-Akki ~ $ whoami 
user
user@redaakash-Akki ~ $ 
user@redaakash-Akki ~ $ sudo su - techsolbox 
No directory, logging in with HOME=/
techsolbox@redaakash-Akki / $ 
techsolbox@redaakash-Akki / $
14. tail command #

The Linux tail command displays data from the end of a file.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ cat files3.txt 
TechSolBox is a leading Website Development company in Gurgaon. We offer Python, Linux development and Digital Marketing service to grow the business.
New Data
Hello User
Hello User from TechSolBox
Linux is an open-source kernel.
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ tail -n 2 files3.txt 
Hello User from TechSolBox
Linux is an open-source kernel.
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
15. df command #

df is a standard Unix command used to display the amount of available disk space for file systems on which the invoking user has appropriate read access.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.8G     0  7.8G   0% /dev
tmpfs           1.6G  162M  1.5G  11% /run
/dev/sda1       902G  354G  502G  42% /
tmpfs           7.8G  177M  7.7G   3% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/loop0       90M   90M     0 100% /snap/core/6673
/dev/loop3       89M   89M     0 100% /snap/core/6964
/dev/loop2       90M   90M     0 100% /snap/core/6818
/dev/loop1      374M  374M     0 100% /snap/anbox/154
cgmfs           100K     0  100K   0% /run/cgmanager/fs
tmpfs           100K     0  100K   0% /var/lib/lxd/shmounts
tmpfs           100K     0  100K   0% /var/lib/lxd/devlxd
tmpfs           1.6G   48K  1.6G   1% /run/user/1000
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
16. du command #

The du command, short for disk usage reports the estimated amount of disk space used by given files or directories.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ du -sh files3.txt 
4.0K    files3.txt
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ du -sh DataFile.txt 
40M DataFile.txt
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
17. free command #

The free command gives information about used and unused memory usage and swap memory of a system. By default, it displays memory in kb (kilobytes).

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ free -h
              total        used        free      shared  buff/cache   available
Mem:            15G        3.0G        6.4G        612M        6.1G         11G
Swap:           15G          0B         15G
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
18. ifconfig command #

ifconfig is a system administration utility in Unix-like operating systems for network interface configuration.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ ifconfig lo
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:40242 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40242 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2891681 (2.8 MB)  TX bytes:2891681 (2.8 MB)

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 

19. uname command #

uname is a command-line utility that prints basic information about the operating system name and system hardware.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ uname -a
Linux redaakash-Akki 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
techsolbox@redaakash-Akki /mnt/techsolbox_dir $ 
20. man command #

The man command is used to view a system’s reference manuals. The command gives users access to manual pages for command-line utilities and tools.

techsolbox@redaakash-Akki /mnt/techsolbox_dir $ man touch

Conclusion

In this tutorial, You learned about the top 20 basic Linux commands and how you can use these commands. Now you can easily use these commands in your Linux system. Explore more Linux tutorials from our community.

image.png

View original on FreeLists


Previous thread · Next thread

Back to July 2020