Table of contents
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.
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
- cd.. refer to as back to the current directory
cd..
- ls -a will list all files including hidden files
ls -a
- we can create any file using touch command on a specific directory
touch
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
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
- The ls -R command show all the path of the sub directory
ls -R
- make myfile.txt file and add content on the file
cat > myfile.txt
- 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
- create a new middle directory
mkdir -P randor/mid/hello
make a google.txt file in home directory
Make a home.txt file in linuxtest directory
touch google.txt
touch test/home.txt
- Copy the content of file.txt and paste it to copy_myfile.txt
cp file.txt copy_myfile.txt
- Add content on file.txt by echo command
echo linuxtest > file.txt
- Move the file one directory to another by using mv command
mv copy_myfile.txt linuxtest
- Move the content of myfile.txt to file.txt
mv myfile.txt file.txt
- Move a copy of content one file to another. Here both operation should run copy and move.
mv copy_file.txt ../file.txt
- Copy directory by using cp -R command.
cp -R linuxtest copy_linuxtest
- Remove a specific directory by using rm -R command.
rm -R copy_linuxtest
- Move a particular directory to another directory using mv command.
mv copy_linuxtest test
- 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
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
The du command allows a user to gain disk usage information
du
du -l
du -h
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
- diff is a command-line utility that allows you to compare two files line by line.
diff file.txt hello.txt
locate command use to find the path of a specific file
locate "file.txt"
The find command use to show all the files in a specific directory even hidden files
find.
find..
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
- 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"
- find . -type f -iname command use to find a specific file in a particular directory without any case sensitivity
find . -type f -iname "*.txt"
- 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
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
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
find . -empty find those files which are empty in a specific directory
find . -empty
- 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
- 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
- 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 {} +
- 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
grep -win "aditya" names.txt
grep -rwin "adity".
grep -win "aditya" ./*.txt
grep -rwin "adity"./*.txt
- print all the command that we have been using like list.
history | grep "ls"
- print all the command that we have been using like ls -l .
history | grep "ls -l"
- 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
- 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
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
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
- 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
- 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
cut -c 1-2 company.txt
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
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"
- write something on a particular file using echo command
echo "Hey" >> names.txt