Essential Linux Command for Beginners
Essential Linux Command for Beginners
Few essential things you should know before using linux:
-
when you are asked to enter password in command prompt, it will not show anythings like **** or ●●●●. So don’t panic just type password and enter the password.
-
Linux command are case sensitive you have to write upper case if it is in uppercase and like wise in lowercase.
-
Never ever use command rm -rf/ ,this will delete all directories and data on it . Here rm means remove , -r means recursive, f means force and / means home.
-
You can get linux OS on free so, no need to pay for it.
-
If you are not familiar with linux then start with GUI based OS like Ubuntu, Fedora or Mint.
Basic Linux commands:
pwd
pwd means Print Work Directory. This command will let you know the path of current directory. Use it when you are lost and pretty useful if you are beginner.
matlab@matlab:~$ pwd
/home/matlab
ls
ls means list. This command shows the folders and files in current directory. You can use it with pwd and mostly used before cd if you don’t know where to go next or which file to use.
matlab@matlab:~$ ls
Desktop Downloads Music Public Templates
Documents examples.desktop Pictures snap Videos
cd
cd means Change directory. This is used to in and out of directory.
For In:
matlab@matlab:~$ cd Music
matlab@matlab:~/Music$
For Out:
matlab@matlab:~/Music$ cd ..
matlab@matlab:~$
mkdir
mkdir means make directory. Used to create new folder using command line.
matlab@matlab:~$ mkdir demo
matlab@matlab:~$ ls
demo Documents examples.desktop Pictures snap Videos
Desktop Downloads Music Public Templates
rmdir
rmdir means remove directory. Used to remove folder from current directory.
matlab@matlab:~$ rmdir demo
matlab@matlab:~$ ls
Desktop Downloads Music Public Templates
Documents examples.desktop Pictures snap Videos
cp
cp means copy. This command is used to make copy of file in same directory or you can give source and destination path of file.
Same directory:
matlab@matlab~$ cp examples.desktop examples1.desktop
matlab@matlab:~$ ls
Desktop Downloads examples.desktop Pictures snap Videos
Documents examples1.desktop Music Public Templates
For different directory:
matlab@matlab~$cp examples.desktop /Desktop/examples.desktop
mv
mv means move. This is used to move file or group of file from one to another directory. It is the replacement of cut operation used in GUI. You can use -f for forcing to move large file.
matlab@matlab:~$ mv matlab.txt /home/matlab/Downloads
sudo
sudo means super user do. This give root permission for specific command. In case you are not given to run any command you can use this command.
matlab@matlab:~$ mv examples.desktop /Desktop
mv: cannot move 'examples.desktop' to '/Desktop': Permission denied
matlab@matlab:~$ sudo mv examples.desktop /Desktop
[sudo] password for matlab:
chmod
chmod means change mode. This give access permission to users like super user, guest, user.
Chmod 777 examples.desktop
777 means full permission for all type of user. Read or r= read permission, value 4 Write or w=Write permission, value 2 Execute or x= Execute permission, value 1 no permission, value 0 r=4+w=2+x=1 ==7, this means full permission to every user 777→first 7 for super user, second for user and third for other like guest. If you don’t want guest or any user should not have write permission then you can give 775 (rwx, rwx,rx)
man
man means manual. This is used to get information about specific command.
matlab@matlab:~$ man sudo
lsblk
lsblk means lists all blocks. This is used to list all available block in the system you are using.
matlab@matlab:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 88.5M 1 loop /snap/core/7270
loop1 7:1 0 54.4M 1 loop /snap/core18/1066
loop2 7:2 0 42.8M 1 loop /snap/gtk-common-themes/1313
loop3 7:3 0 149.9M 1 loop /snap/gnome-3-28-1804/67
loop4 7:4 0 4M 1 loop /snap/gnome-calculator/406
loop5 7:5 0 14.8M 1 loop /snap/gnome-characters/296
loop6 7:6 0 1008K 1 loop /snap/gnome-logs/61
loop7 7:7 0 3.7M 1 loop /snap/gnome-system-monitor/100
loop8 7:8 0 219.1M 1 loop /snap/gimp/189
sda 8:0 0 465.8G 0 disk
└─sda1 8:1 0 465.8G 0 part /
sdb 8:16 0 223.6G 0 disk
├─sdb1 8:17 0 529M 0 part
├─sdb2 8:18 0 100M 0 part /boot/efi
├─sdb3 8:19 0 16M 0 part [SWAP]
└─sdb4 8:20 0 223G 0 part
mount/unmount
mount is used for taking access for specific disk or folder like USB or local drive.
mount <directory path>
unmount is used to remove access permission for specific disk or folder.
unmount <directory path>
df
df means disk file system. It provide available space in any directory.
uname means unix name. This provide the name of current system.
matlab@matlab:~$ uname
Linux
ps
ps means process status. It gives the process status running.
matlab@matlab:~$ ps
PID TTY TIME CMD
13682 pts/0 00:00:00 bash
14875 pts/0 00:00:00 ps
kill
kill is used for terminating process using process id or PID. Ti is a builtin command of linux.
service
Service command is used to run System V init script. It is used for start, stop and restart linux services.
batch
Batch command is used to execute the commands in serial order stored in file with extension .bat
shutdown
shutdown command is used to shutdown the system.
touch
touch is used to create new empty file.
matlab@matlab:~$ touch demo
matlab@matlab:~$ ls
demo Desktop Documents Downloads examples1.desktop Music Pictures Public snap
Templates Videos
cat
cat command is mostly used command in linux. It shows the content of file.
matlab@matlab:~$ cat demo
use of cat command
head/tail
head shows top 10 lines in file and tail shows last 10 lines of file.
comm
comm is used to compare each line in both files and print it
less/more
less command is used to show content of file on separate file and more is used to show content in command prompt.
more command:
less command:
Cmp
cmp command compare files and return difference in files
matlab@matlab:~$ cmp demo demo1
demo demo1 differ: byte 507, line 35
alias
it is used to make short form of command. Like clear to cls, now cls can clear the terminal
matlab@matlab:~$ alias cls=clear
matlab@matlab:~$ cls
cal
cal means calendar. It shows the calendar of the system
history
history shows every command you executed in terminal above
matlab@matlab-Inspiron-5584:~$ history
1 sudo apt install gimp
2 sudo apt install GIMP
3 sudo apt install vlc
4 update mozilla
5 sudo apt install mozilla
6 sudo apt install firefox
7 sudo apt install gimp
8 sudo apt install GNU Image Manipulation Program
9 sudo apt get dist-upgrade
yes
Its a funny command just type yes command followed by some text. You will know yourself.
rev
rev command is used to reverse the text of a file.
matlab@matlab:~$ touch demofile.txt
matlab@matlab:~$ cat demofile.txt
this is demo
matlab@matlab:~$ rev demofile.txt
omed si siht
wget
wget is used to download file form the web using command wget <link>
locate
locate is used to filed the location any file name or folder name.
grep
grep command is used to select the specific pattern in a file.
clear
clear is used to clear the terminal. Try using it. Your command are send up and not shown in display , after scroll up you will see your previous command.
echo
echo is used to print the test or string you will write after echo command.
matlab@matlab:~$ echo matlab
matlab
sort
sort is used to sort lines of data in a file.
matlab@matlab:~$ sort demo
demo Desktop
demo Desktop
demo Desktop
Documents Downloads
Documents Downloads
Documents Downloads
examples1.desktop
examples1.desktop
examples1.desktop
head command
head command
head command
chown
chown means change owner. This command is used to change the owner ship of the file or directories.
matlab@matlab:~$ chown matlab demofile.txt
whoami
whoami shows the name of current user.
matlab@matlab:~$ whoami
matlab
w
w command is used to file current user logged in and what is the user is doing.
matlab@matlab:~$ w
18:07:47 up 4:12, 1 user, load average: 0.40, 0.33, 0.37
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
matlab :0 :0 01:26 ?xdm? 8:09 0.03s /usr/lib/gdm3/gdm-x-session --run-script env GNOME_SHELL_SESSION_MODE=ubuntu gnome-session --session=ubuntu
gzip
gzip command is used to create compress one or more files at once.
matlab@matlab:~$ gzip demo demo1 demofile.txt
matlab@matlab:~$ ls
demo1.gz demofile.txt.gz demo.gz