Linux Commands
Linux Commands
This command is used to display text files; combining copies of text; creating
new text files.
Syntax: cat- [option] filename
cat: If we write this command, then whatever we write it will echo the same.
cat filename: It will show all the contents present in the given file.
cat filename1 filename2: It will show the contents of file1 in file2.
cat -n filename: It will add line numbers to all the lines either lines are blank or
written.
cat filename1 filename2 > filename3: This will combine the content of file1
and file2 and will show in file3.
cat filename1 >>filename2: This will append the content of file1 to file2.
ls
ls command is used to display a list of files in any directory, by default the
simple ls command displays the list of files or subdirectory in 5 columns
Syntax: ls – [options] file/ directory name
ls: It will show the content of home directory.
ls
[directory name]: It will display the contents inside the given directory.
ls .. /.. : It will give the content of two directories back than the current
directory.
ls -l: It will give the complete information about the files and directory present
in the working directory.
ls -a: It gives the content of all the directory along with all the hidden files and
directories present in the working directory.
ls -al: This is the combination of above two options (-a & -l). It will give all the
contents of hidden and non-hidden files in long or list format with complete
information.
ls- ls: Here ‘s’ denotes sorting on the basis of size and -l for list or complete
information.
ls documents / *.html: Here * means all. It will give all the files with .html
extension inside the directory document.
ls -ls >out.txt: Here -ls means it will sort the content of directory on the basis
out.txt along with ls will make a new file named as out.txt which stores the
output ls -ls.
cd [directory name]: It will take you to the inside directory name folder.
cd dir_name1 /dir_name2 /: Multiple directories can also be given like this and
you will reach inside directory name to folder.
cp
cp It stands for copying
cp file1.txt file2.txt: This command will copy all the contents of file1.txt to
file2.txt and it will create a new file named as file2.txt if it is not already
created.
cp -i file1.txt file2.txt dir1: Here ‘i’ stands for interactive control. This
command will copy file1.txt and file2.txt in the given directory but if file1.txt
and file2.txt is already present then it will ask user whether he wants to
overwrite it or not.
cp -r dir1 dir2: It will copy all the contents of dir1 and dir2 but if dir2 is not
made then it will show us error.
mv
mv It stands for moving text files
mv file1.txt file2.txt: This command will copy all the contents of file1.txt to
file2.txt and it will create a new file named as file2.txt if it is not already
created.
mv -i file1.txt file2.txt dir: Here i stands for interactive control. This command
will move file1.txt and and file2.txt in the given directory if file1.txt and file2.txt
is already present then it will ask user whether he wants to overwrite it or not.
mv dir1 dir2: It will copy all the contents of dir1 and dir2 but if dir2 is not made
then it will show us error.
mkdir
mkdir command is used for making directory
Syntax: mkdir directory_name
mkdir -p New/B: -p option creates both parent and child directory in the single
shot otherwise it will give error.
mkdir -p New1/ {A, B,C}: It will create multiple subdirectory (A,B,C,D,E and so
on) inside the parent directory.
rmdir
rmdir stands for remove directory Syntax:
rmdir –[option] directory_name
rmdir dir_name: It will remove the directory. rmdir a/b/c/d/e: It will remove
directory e. rmdir -p a/b/c/d/e: Here p stands for parent. It will delete all the
directories in single shot.
rmdir -pv a/b/c/d/e: It will delete whole directory structure and -v will show
how it is happening.
If we want to delete the directory, firstly we have to remove all the files from
the directory as because rmdir command will only delete directories and not
files.
rm
rm file_name: It will remove the file.
kill
kill command is used to kill the process in order to delete a process we need to
know the process ID of that process.
kill – KILL pid: It will forcefully kill the process. top It shows real-time dynamic
view of computer meaning which process is running and which process is
taking most part of your computer memory in general it shows which process is
taking most part of CPU and RAM.
top
top: It will give all information about process and refreshes in every 3 seconds
after giving top command.
• If we press S then we can change the time of refreshing which is by
default 3 second.
• If we press i after top it will filter out idle processes and only show the
process which are running.
• If we press K after top then it will ask for PID and when we press enter it
will kill the process.
echo
It prints what is written after echo. It is somewhat like print statement.
Example- echo
“hello world”
x=10 echo “the value of x is $x” output: the value of x is 10
myvar = “hello” echo $ myvar
less
This command is used to read the files and help in searching something any
type of pattern or some words.
less file_name1: This command will help you in reading big files because using
cat command if we open a file then it doesn't display the whole content.
The file displayed using less command can be navigated line by line using arrow
keys.
The file displayed using less command can be navigated page by page using
space bar.
If we want to go back page by page B is used.
G will lead you to go to the end of the file. g
will take you to the top of the text file.
-+
/ word: This command will search the given word from top to bottom of the
given text file.
? word: This command will search the given word from bottom to top.
Press Q: To quit less command.
touch
This command is used to create empty file in Linux and also used to change
time instance of a file.
touch file1.txt: If the file is not created this command will create the file but if
it is already created it will only change the time stamp of the file to the current
time.
chmod
File permission r w x r w x r w x
• 1 st three owner
• 2nd three group
• other - denoting file
d r w x r w x r w x owner
=r w x 4 2 1 Group =r w x
421
Other =r w x 4 2 1
sudo
sudo stands for super user do.
It gives some extra privileges as an administrator or power users. This
command generally helps in the place where permission denied occurs.
• when mkdir new directory does not create directory and says
permission denied then we use sudo command, after writing this
command it will ask for password. Once we provide it will create the new
directory, generally it is used for installing third party application
• sudo mkdir new directory It will work to create new directory
• sudo -s It will take you to the super user mode after entering the
password
WINDOWS COMMANDS
• rename:
Syntax- ren “folder_name” “new name”
This is used to rename a folder name.
• delete
Syntax- delete file1.txt
It will delete file1.txt
del *.* : It will delete all files with extensions
• open - dir file1.txt
• tasklist: It will give list of all the programs that are running.
• find:
Syntax- find “working” file1.txt
It will tell whether working is present in file1.txt or not.
• echo
eg - color 02
Here 2 denotes font colour and 0 denotes background colour.
It will use to change color of background and font.
- date and time Above both commands will work in administrator mode We
open this by write click, then administrator mode.
• Shutdown
- Shutdown /s: Initiate shutdown.
• Netstat: It will tell all the connections made from the PC.