Basic to Advance Linux Commands

Basic to Advance Linux Commands

Table of contents

No heading

No headings in the article.

The Linux command is a utility of the Linux operating system. All basic and advanced tasks can be done by executing commands. The commands are executed on the Linux terminal. The terminal is a command-line interface to interact with the system, which is similar to the command prompt in the Windows OS.

e87e53557a3feb72d3a0993fdb12fdf5.gif

Commands in Linux are case-sensitive. The terminal can be used to accomplish all Administrative tasks. This includes package installation, file manipulation, and user management. Linux terminal is user-interactive. All the basic to advance linux commands are shown below:

  • cd refer to as change directory that change directory command.
  • To make a new directory use the command mkdir
cd

mkdir

001.png

  • cd.. refer to as back to the current directory
cd..

002.png

  • ls -a will list all files including hidden files
ls -a

003.png

  • we can create any file using touch command on a specific directory
touch

004.png

  • cat command print the content of a file onto the standard output stream

  • The vi always starts in command mode. To enter text, you must be in insert mode by press i from the keyboard ⌨.

cat 

vi

005.png

006.png

007.png

008.png

  • The ls -l command Show hidden function

  • The ls -al command Show every hidden files

  • The ls command lists the files inside a folder

ls -l

ls -al

ls

009.png

  • The ls -R command show all the path of the sub directory
ls -R

0010.png

  • make myfile.txt file and add content on the file
cat > myfile.txt

0011.png

  • The Linux tar stands for tape archive, is used to create Archive and extract the Archive files. Here we just convert small character to capital character of a perticular string
cat file.txt | tr a-z A-Z > upper.txt

cat upper.txt

0012.png

  • create a new middle directory
mkdir -P randor/mid/hello

0013.png

  • make a google.txt file in home directory

  • Make a home.txt file in linuxtest directory

touch google.txt

touch test/home.txt

0014.png

  • Copy the content of file.txt and paste it to copy_myfile.txt
cp file.txt copy_myfile.txt

0015.png

  • Add content on file.txt by echo command
echo linuxtest > file.txt

0016.png

  • Move the file one directory to another by using mv command
mv copy_myfile.txt linuxtest

0017.png

  • Move the content of myfile.txt to file.txt
mv myfile.txt file.txt

0018.png

  • Move a copy of content one file to another. Here both operation should run copy and move.
mv copy_file.txt ../file.txt

0019.png

  • Copy directory by using cp -R command.
cp -R linuxtest copy_linuxtest

0020.png

  • Remove a specific directory by using rm -R command.
rm -R copy_linuxtest

0021.png

  • Move a particular directory to another directory using mv command.
mv copy_linuxtest test

0022.png

  • Sudo refres to as superuser do or substitute user do. Sudo allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands.
sudo echo hello world

0023.png

  • The df command displays the amount of disk space available on the file system with each file name's argument.

  • The df -m command displays the amount of disk space available on the file system in megabyte unit.

  • The df -hg command displays the amount of disk space available on the file system in gigabyte unit.

df
df -m
df -hg

0024.png

  • The du command allows a user to gain disk usage information

du
du -l
du -h

0025.png

  • head command display total number of lines in a file

  • head -n4 display first 4 lines in a specific file

  • tail command display last ten lines in a specific file

  • tail -n2 command display last 2 lines of a specific file

head file.txt

head -n4 file.txt

tail file.txt

tail -n2 file.txt

0026.png

  • diff is a command-line utility that allows you to compare two files line by line.
diff file.txt hello.txt

0027.png

locate command use to find the path of a specific file

locate "file.txt"

0028.png

The find command use to show all the files in a specific directory even hidden files

find.

find..

0029.png

  • The find . -type d command use to show all the directory in a specific location even hidden directory

  • The find . -type f command use to show all the files in a specific directory even hidden files

find . -type d

find . -type f

0030.png

  • find . -type f -name command use to find a specific file in a particular directory, also use to find similar file format.
find . -type f -name "file.txt"

find . -type f -name "file*"

find . -type f -name "*.txt"

0031.png

  • find . -type f -iname command use to find a specific file in a particular directory without any case sensitivity
find . -type f -iname "*.txt"

0032.png

  • find . -type f -mmin use to find a specific file on after timeline or before timeline
find . -type f -mmin +20

find . -type f -mmin +20 -mmin -10

0033.png

find . -type f -mmin -20

find . -type d -mmin -20 

find . -type f -mmin -10

find . -type f -mmin +2 -mmin -10

find . -type f -mtime -10

0034.png

  • find . type f -maxdepth command find those files that consist of 1 megabyte

  • find . -size +1k command find those files that consist of more than 1 kilobyte

find . type f -maxdepth 1

find . -size +1k

0035.png

find . -empty find those files which are empty in a specific directory

find . -empty

0036.png

  • prem refer to as linux permissions

here we can calculate the permission by using this method

4 ---->Read permission 2 ---->Write permission 1 ---->Execute permission 0 ---->No permission

chmod +rwx filename to add permissions. chmod -rwx directoryname to remove permissions. chmod +x filename to allow executable permissions. chmod -wx filename to take out write and executable permissions.

777 means makes every single file on the system under / (root) have rwxrwxrwx permissions.

find . -perm 777

find . -perm 770

find . -perm 440

chmod u=rwx,g=rx,o=r file.txt

chmod 777 file.txt

chmod 577 file.txt

chmod 500 file.txt

chmod 777 upper.txt

0037.png

  • chown command is used to change the file Owner or group. That is when ever we make some changes it want a root password. Because we can't read, write or execute operation of owner without admin.
chown root file.txt

sudo chown root file.txt

cat file.txt

sudo cat file.txt

0038.png

  • remove all the .txt files by using remove and add a place holder where all the files are goes into it incremen order and remove.
find . -type f -name "*.txt" -exec rm -rf {} +

0039.png

  • grep basically something from a particular file and display it.
grep "aditya" names.txt

grep -w "das" names.txt

grep -i "ADITYA DAS" names.txt

grep -n "aditya" names.txt

grep -B 3 "sumit" names.txt

0040.png

grep -win "aditya" names.txt

grep -rwin "adity".

0041.png

grep -win "aditya" ./*.txt

grep -rwin "adity"./*.txt

0042.png

  • print all the command that we have been using like list.
history | grep "ls"

0043.png

  • print all the command that we have been using like ls -l .
history | grep "ls -l"

0044.png

  • display the regular expression or a match a particular pattern using grep -P command
grep -P "\w" company.txt

grep -P "\d{3}-\d{3} -d{4}" company.txt

0045.png

  • list all the history of commands that we have been use and run the previous command by using a unique command id.
history | grep "ls -l"

! 1155

0046.png

  • all the content of a particular file print on a reverse sorted order by using sort -r command

  • all the content of a particular file print on a sorted order by using sort command

  • all the content of a particular file print on a numeric order by using sort -n command

sort -r company.txt

sort company.txt

sort -n company.txt

0047.png

  • hostname command in Linux is used to obtain the DNS(Domain Name System) name and set the system's hostname or NIS(Network Information System) domain name.

  • The uname command writes to standard output the name of the operating system that you are using.

hostname

hostname -i

uname -o

uname -m

uname -r

lscpu

0048.png

  • The vmstat command (short for virtual memory statistics) is a built-in monitoring utility in Linux. The command is used to obtain information about memory, system processes, paging, interrupts, block I/O, disk, and CPU scheduling.
vmstat

vmstat -S m

0049.png

  • zip and unzip a particular file using zip & unzip command
zip files.zip company.txt

zip files2.zip company.txt file.txt

unzipfiles files2.zip

0050.png

cut -c 1-2 company.txt

0051.png

  • ifconfig basically display internet configuration related information in your local system

  • The sed program is a stream editor that receives its input from standard input, changes that input as directed by commands in a command file, and writes the resulting stream to standard output.

ifconfig

sed

0052.png

  • echo command print the first content then the second content

  • By using or the compiler execute only one of the content so the first content should print

echo "first" && echo "second"

echo "first" || echo "second"

xyz || echo "second"

0053.png

  • write something on a particular file using echo command
echo "Hey" >> names.txt

0054.png

Did you find this article valuable?

Support ADITYA DAS by becoming a sponsor. Any amount is appreciated!