If you want to create more and more empty directory like: movie >> english >> video
Ex. mkdir -p /movie/english/video
Note1: This folders are created in root directory so you have to need root permission so type sudo before mkdir )
Note2: if you want to create this folder in other location for example in home directory. (mkdir -p /home/firoj/movie/english/video) (Note: firoj is my username)
rmdir 'folder name'
remove directory.
rmdir -p 'folders name'
After creating multiple empty folder by using mkdir -p, then next step is how to remove it. Using rmdir command you cannot delete if the Directory is not empty.
So using rmdir -p command you can delete all folder and sub-folders.
Ex. rmdir -p /home/firoj/movie/english/video (Note: firoj is my user name.)
gedit 'file name'
Create and edit file. Gedit is a graphical text editor.
nano 'file name'
create and edit file, it is same as gedit.
Type something
press F3 to save (without exit)
Ctrl + X, to save and exit. (press 'Y' for save, 'N' for quit without save.
rm 'file name'
remove files
rm -i 'file name'
Prompt before every removal. so that you can prevent yourself from accidentally removing a file.
rm -r 'file name'
remove folder
ls
list all files and directory, in column format.
ls /directory
list all files and folder in the specified directory.
Ex. ls /tmp (It display all files and folder under the tmp directory)
ls -l
list all files and folder in long format means one file per line. That means it shows details about the file and folder.
ls -a
lists all files including hidden files.
ls -al
list all files including hidden files in long format.
pwd
Display your current directory.
cd
go to the home directory.
cd /etc
change to etc directory. using this command you can change directory with specified path.
cd .. (space between cd and ..)
go to the parent directory.
cd /
go to the root directory.
cd ~
'~' is an alias for home directory. It can be used as a shortcut to your home.
cd -
go to the previous directory.
If you are in home directory and you type this command cd - (output: / ) means go the root directory.
head 'file name'
Display the first few line of a text file. It is same as cat command but it display only header means first few lines.
tail 'file name'
It same as head and cat command. But it display last few lines of a text file.
cp (copy one file)
Ex. cp test test1(test & test1 are files)
It means copy the test file and paste in same location with new name that is test1.
You can paste any where.
cp /home/firoj/filename /tmp (copy to another directory)
copies a file from one location to another.
Note: To move other directory it shows the error 'permission denied'. so type sudo command before cp command.
sudo cp /home/firoj/filename /tmp ('firoj' is the user name of my computer)
cp -r (copy whole directory)
using this command you can copy a folder and its sub-folder.
Ex. cp -r /home/firoj/Desktop/test /home
It means, copy a test folder from Desktop and paste in home Directory. you can use (~) symbol instead of /home.
Copy Multiple file to Directory
Ex. cp test test1 /home/firoj/'foldername'
Here test and test1 are two file. I copied from Desktop and paste in specific directory.
cp -i
to prevent overwriting
mv /home/firoj/filename /tmp
This command is use to move a file to a new location or to rename files.
To rename: mv /home/firoj/test /home/firoj/test2
Note: firoj is my user name, test is the file name.
man 'command'
This command helps to find the information about a particular command. manmeans manual pages, known as 'man pages'.
Example_1: man cp (get help on the cp command)
Example_2: man ls
whatis
To see the description.
Ex. whatis cp (Output: copy file and directories)
Ex. whatis ls (Output: list directories content)
whereis
Locates the program, source code, and manual page for a command.
Ex. whereis ls (output: ls: /bin/ls /user/share/man/man1/ls.1.gz
which
shows the full path of shell commands.
Ex. which cp (output: /bin/cp)
file
Linux does not use extensions to determine the file type so this command is use the determine the file type
Ex. file data (data is a text file name)
Output: ASCII text
touch 'file name'
Create an empty file
cat 'file name'
show the content of a text file on screen.
cat -n 'file name'
Show content file, with line numbers.
cat > 'file name'
you can create file using cat > command.
Note: press Ctrl + D to save and exit. Ctrl+d means it will send an EOF (End of File) to the running process to ending the cat command.
Custom End Maker for cat
you can choose an end maker for cat with <<.
Ex. cat > 'file name' << end
When you type end and press enter, it end the process and save document.
cat test > test1 (copy file usingcat)
It means copy test file and paste it in same location with new file that is test1.
0 Comments