This article is all about some important Basic Linux commands with examples. Here we learn many of the commands such as command for adding local user, command for delete local user, grant file permissions to a file, change group ownership of a file, adding a new group, commands for information gathering about operating system, commands for creating files and folders, commands for change ownership of a file and so on. Generally, these all commands are works on all the Linux distributions same as given below. No further change is done in these commands to do so work on any of the Linux distribution which is present on the internet. So here we learn how to execute these given commands on our Linux operating system with ease.
The adduser command is used to add a new user to a system. For example to add a new user Satish, execute the following command:
[email protected]:~# adduser satish Adding user `satish' ... Adding new group `satish' (1004) ... Adding new user `satish' (1003) with group `satish' ... Creating home directory `/home/satish' ... Copying files from `/etc/skel' ... Enter new UNIX password:
The addgroup command is used to add a new group to a system. For example to add a group named as Satish, execute the following command:
[email protected]:~# addgroup satish Adding group `satish' (GID 1004) ... Done.
The arch command is used to print the architecture of the machine. For example:
[email protected]:~# arch i686
The cal and ncal both commands are used to display a calendar on the screen as an output, but cal command display the calendar in a horizontal manner and ncal command displays the calendar in a vertical manner. For example:
[email protected]:~# cal July 2017 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
[email protected]:~# ncal July 2017 Su 2 9 16 23 30 Mo 3 10 17 24 31 Tu 4 11 18 25 We 5 12 19 26 Th 6 13 20 27 Fr 7 14 21 28 Sa 1 8 15 22 29
The cat command is used to join two files together, and print the data of these files on the standard output. It means this command prints the information which is provided to it, whether in the standard input form or form of a file. For example to print the output of a.txt file, execute the following command:
[email protected]:~# cat a.txt Hi..what are you doing?
The cd command is used to change the present working directory(pwd) of a user. For example, to go to the music directory from root directory, execute the following command:
[email protected]:~# cd Music [email protected]:~/Music#
The chgrp command is used to change the group ownership of a file. In this command the first argument will be new group name and the second argument will be the name of the file. For example, to change the group ownership of an a.txt file to root, execute the following command.
[email protected]:~# chgrp root a.txt
The chmod command is used to change access permissions of a file. You can give permission to a file using the numeric method and alphabetic method. Here r stands for reading permission, w stands for writing permission, and x stands for execute permission. We explain this command in detail in my earlier articles. So follow our blog for updates and stay updated.
[email protected]:~# chmod 777 rahul.txt [email protected]:~# chmod rwx satish.txt
The chown command is used to change the ownership and group of a file. For example, if you want to change the ownership of file a.txt to root and set its group as root, then execute the following command:
[email protected]:~# chown root:root a.txt
The cksum command is used to prints the CRC checksum and byte count for the input file. For example to print the CRC checksum and byte count for the a.txt file, execute the following command:
[email protected]:~# cksum a.txt 1226195471 17 a.txt
The clear command is used to clear the terminal screen.
[email protected]:~# clear
The cmp command is used for byte-by-byte comparison of two files. For example, to compare a.txt and b.txt file, execute the following command:
[email protected]:~# cmp a.txt b.txt a.txt b.txt differ: byte 2, line 1
Here, instead of a.txt and b.txt you can use your file name.
The comm command is used to compare two sorted files line-by-line. For example, if file1 contains numbers 1 to 4 and file2 contains number 3 to 6 then on executing the comm command you will get:
[email protected]:~# comm a.txt b.txt 1 2 3 4 5 6
Here, a.txt and b.txt will be your file1 and file2 name.
The cp command is used to copy files and directories. from one place to another place example given below.
[email protected]:~# ls a.txt Desktop Documents Downloads Music Pictures Public Templates Videos [email protected]:~# cp a.txt Desktop/ [email protected]:~# cd Desktop/ [email protected]:~/Desktop# ls a.txt rahl [email protected]:~/Desktop#
The csplit command is used to split a file into sections determined by context lines.
[email protected]:~# csplit a.txt 1 5 10 0 38 76 24
The output of this command is shown by executing ls command on your system which is given below.
[email protected]:~# ls a.txt Desktop Documents Downloads Music Pictures Public Templates Videos <strong>xx00 xx01 xx02 xx03</strong>
The date command is used to show the system date and time.
[email protected]:~# date Thu Jul 13 22:14:16 IST 2017
The dd command in Linux is used for clone one hard disk to another hard disk. The dd command stands for “Disk Duplicator” and used for converting and copying data. This is very useful and dangerous tool for Linux operating system. Because it can use in many ways other than cloning of the hard disk. So we learn dd command in a detailed way in upcoming articles. Here the main use of dd command is given below that is cloning of hard disk.
[email protected]:~# dd if=/dev/sda of=/dev/sdb
The df command is used to display the system disk space usage in output.
[email protected]:~# df /dev/sda Filesystem 1K-blocks Used Available Use% Mounted on udev 4078324 0 4078324 0% /dev
The diff command is used to compare two file line by line in Linux operating system.
[email protected]:~# diff a.txt b.txt 1,12c1,5 < hiii < hello < how are you < what the hell? < i am fine < what about you < What the hell are going on here < I think < Its enough < For today < Rahul < Hackgyd --- > good morning > everyone > once again > i am here > with a new article [email protected]:~#
The diff3 command is used to compare three files line by line as the name suggests.
[email protected]:~# diff3 a.txt b.txt c.txt ==== 1:1,12c hiii hello how are you what the hell? i am fine what about you What the hell are going on here I think Its enough For today Rahul Hackgyd 2:1,5c good morning everyone once again i am here with a new article 3:1,3c hii everyone goodmorning
The dir command is used to list the directory contents. For example
[email protected]:~# dir Desktop Music Templates Downloads Documents Pictures satish Videos
The dirname command strips the last part of a given filename. This command removes the trailing/component from the NAME and prints the remaining portion. If it prints ‘.’ that means current directory.
[email protected]:~# dirname Desktop/ . [email protected]:~# dirname Desktop/a.txt Desktop
The dmidecode command is used to prints the system’s DMI table contents in a human-readable format. This command is also used for getting Hardware information. For example:
[email protected]:~# dmidecode # dmidecode 3.1 Getting SMBIOS data from sysfs. SMBIOS 2.5 present. 10 structures occupying 449 bytes. Table at 0x000E1000. Handle 0x0000, DMI type 0, 20 bytes BIOS Information Vendor: innotek GmbH Version: VirtualBox Release Date: 12/01/2006 Address: 0xE0000 Runtime Size: 128 kB ROM Size: 128 kB Characteristics: ISA is supported PCI is supported Boot from CD is supported Selectable boot is supported 8042 keyboard services are supported (int 9h) CGA/mono video services are supported (int 10h) ACPI is supported Handle 0x0001, DMI type 1, 27 bytes System Information Manufacturer: innotek GmbH Product Name: VirtualBox Version: 1.2 Serial Number: 0 UUID: 0E321BAC-7BA8-42F9-8DC0-599A50AF29F9 Wake-up Type: Power Switch SKU Number: Not Specified Family: Virtual Machine</pre> <pre>Handle 0x0008, DMI type 2, 15 bytes Base Board Information Manufacturer: Oracle Corporation Product Name: VirtualBox Version: 1.2 Serial Number: 0 Asset Tag: Not Specified Features: Board is a hosting board Location In Chassis: Not Specified Chassis Handle: 0x0003 Type: Motherboard Contained Object Handles: 0 Handle 0x0003, DMI type 3, 13 bytes Chassis Information Manufacturer: Oracle Corporation Type: Other Lock: Not Present Version: Not Specified Serial Number: Not Specified Asset Tag: Not Specified Boot-up State: Safe Power Supply State: Safe Thermal State: Safe Security Status: None Handle 0x0007, DMI type 126, 42 bytes Inactive Handle 0x0005, DMI type 126, 15 bytes Inactive Handle 0x0006, DMI type 126, 28 bytes Inactive Handle 0x0002, DMI type 11, 7 bytes OEM Strings String 1: vboxVer_5.2.4 String 2: vboxRev_119785 Handle 0x0008, DMI type 128, 8 bytes OEM-specific Type Header and Data: 80 08 08 00 BE 61 29 00 Handle 0xFEFF, DMI type 127, 4 bytes End Of Table
The du command is used to displays the disk usages of files which is present in a directory as well as its sub-directories. For example:
[email protected]:~# du 8 ./.config/evolution/sources 12 ./.config/evolution 4 ./.config/goa-1.0 4 ./.config/systemd/user/sockets.target.wants 4 ./.config/systemd/user/default.target.wants 12 ./.config/systemd/user 16 ./.config/systemd 4 ./.config/enchant 8 ./.config/dconf 8 ./.config/gedit 4 ./.config/ibus/bus 8 ./.config/ibus 4 ./.config/gnome-session/saved-session 8 ./.config/gnome-session 84 ./.config/pulse 8 ./.config/nautilus 172 ./.config 4 ./Downloads 44 ./.vnc 4 ./Music 4 ./Pictures 624 ./.cache/gnome-software/3.26/extensions 96 ./.cache/gnome-software/3.26/ratings 724 ./.cache/gnome-software/3.26 728 ./.cache/gnome-software 936 ./.cache/gstreamer-1.0 4 ./.cache/evolution/sources/trash 8 ./.cache/evolution/sources 4 ./.cache/evolution/addressbook/trash 8 ./.cache/evolution/addressbook 4 ./.cache/evolution/calendar/trash 8 ./.cache/evolution/calendar 4 ./.cache/evolution/mail/trash 8 ./.cache/evolution/mail 4 ./.cache/evolution/memos/trash 8 ./.cache/evolution/memos 4 ./.cache/evolution/tasks/trash 8 ./.cache/evolution/tasks 52 ./.cache/evolution 4 ./.cache/obexd 4 ./.cache/folks/avatars 8 ./.cache/folks 9176 ./.cache/tracker 4 ./.cache/gnome-calculator 60 ./.cache/thumbnails/large 64 ./.cache/thumbnails 4 ./.cache/libgweather 10996 ./.cache 4 ./.gconf 4 ./Templates 4 ./Videos 4 ./.gnupg/private-keys-v1.d 8 ./.gnupg 24 ./Desktop/rahl 32 ./Desktop 4 ./Public 4 ./Documents 4 ./.local/share/evolution/addressbook/trash 4 ./.local/share/evolution/addressbook/system/photos 92 ./.local/share/evolution/addressbook/system 100 ./.local/share/evolution/addressbook 4 ./.local/share/evolution/calendar/trash 8 ./.local/share/evolution/calendar/system 16 ./.local/share/evolution/calendar 4 ./.local/share/evolution/mail/trash 8 ./.local/share/evolution/mail 4 ./.local/share/evolution/memos/trash 8 ./.local/share/evolution/memos 4 ./.local/share/evolution/tasks/trash 8 ./.local/share/evolution/tasks 144 ./.local/share/evolution 8 ./.local/share/gnome-shell 4 ./.local/share/sounds 12 ./.local/share/keyrings 4 ./.local/share/applications 76 ./.local/share/gvfs-metadata 4 ./.local/share/folks 436 ./.local/share/tracker/data 440 ./.local/share/tracker 4 ./.local/share/nautilus/scripts 8 ./.local/share/nautilus 4 ./.local/share/gnome-settings-daemon 988 ./.local/share/app-info/xmls 992 ./.local/share/app-info 4 ./.local/share/icc 1712 ./.local/share 1716 ./.local 13060 .
The echo command is used to display the content which is given to it as a input text. For example:
[email protected]:~# echo hello dear hello dear
The eject command is used to eject the removable disk such as floppy disk, and CD ROM.
[email protected]:~# eject
The env command is used for print a list of the current environment variables, or to run another program in custom environment without modifying the current one.
[email protected]:~# env LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01; 31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31: *.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01; 31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01; 35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35: *.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*. nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35: *.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36: *.spx=00;36:*.xspf=00;36: SSH_CONNECTION=192.168.225.131 21528 192.168.225.211 22 LANG=en_US.UTF-8 S_COLORS=auto XDG_SESSION_ID=4 USER=root PWD=/root HOME=/root SSH_CLIENT=192.168.225.131 21528 22 SSH_TTY=/dev/pts/0 MAIL=/var/mail/root TERM=xterm SHELL=/bin/bash SHLVL=1 LOGNAME=root DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/0/bus XDG_RUNTIME_DIR=/run/user/0 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin _=/usr/bin/env OLDPWD=/root/Desktop
The exit command is used to close the terminal box.
[email protected]:~# exit
This command is used for copies files to the standard output because expand will produce the content of the file in output with only tabs changed to spaces.
r[email protected]:~# expand a.txt hiii hello how are you what the hell? i am fine what about you What the hell are going on here I think Its enough For today Rahul Hackgyd
The expr command is used to evaluate the arithmetic expression. for example:
[email protected]:~# expr 5 + 4 9
The factor command is used to express the prime factor of input number. for example:
[email protected]:~# factor 544 544: 2 2 2 2 2 17
This command is used for searching a string instead of searching for a pattern that matches an expression in a file.
[email protected]:~# fgrep "hello" a.txt hello
The find command is used to search any files in a directory and in its subdirectories. For example:
[email protected]:~# find . -name a.txt ./a.txt ./Desktop/a.txt
This command is a formatter for simplifying and optimizing text files.
[email protected]:~# fmt a.txt hiii hello how are you what the hell? i am fine what about you What the hell are going on here I think Its enough For today Rahul Hackgyd
The fold command is used to wrap each input line to fit in specified width. For example:
[email protected]:~# fold -w 12 hi my name is satish meena. hi my name i s satish mee na.
The free command is used to display the amount of free memory and used memory in the system. For example:
[email protected]:~# free total used free shared buff/cache available Mem: 8182472 771524 6685192 152492 725756 6617384 Swap: 0 0 0
The groups command is used to displays the name of the groups a user is part of.
[email protected]:~# groups root
The gzip command is used to compress the input file, and replace the input file itself with having a .gz extension.
[email protected]:~# gzip b.txt
The gunzip command is used to restored the compressed file into their original form.
[email protected]:~# gunzip b.txt.gz
The head command is used to displays the only first ten lines of the file to standard output. For example:
Sample output of a file
[email protected]:~# cat a.txt hiii hello how are you what the hell? i am fine what about you What the hell are going on here I think Its enough For today Rahul Hackgyd
Output of a file after using head command. Here you can observe that only first 10 lines are shown as the output of the file.
[email protected]:~# head a.txt hiii hello how are you what the hell? i am fine what about you What the hell are going on here I think Its enough For today
These all commands are used in Linux Operating systems same as given above. But here we only learn basic usage of these commands for deep knowledge of these commands read upcoming articles. If you found this article helpful for you then share this with your friends and if you have any queries regarding this then simply solved out your queries with the help of comment section. Also, follow our blog for further updates.