cd (Change Directory)- To go from one directory to another:
| Command | Description |
|---|---|
| cd | To go to home directory |
| cd Year | To go to "Year" directory which is available in current location/path. |
| cd Year/Month | To go to "Month" directory which is located in "/Year" directory |
| cd - | Swap (go back to) previous working directory. |
| cd .. | To go one level back i.e If you are in "Month" directory then you will go in "/Year" directory |
| cd ../.. | To go two level back i.e If you are in "Month" directory then you will go in "/" directory |
[user1@pc1 ~]$ pwd
/home/user1
[user1@pc1 ~]$ ls
Desktop Downloads file1 Pictures Templates Year
Documents emptyFile Music Public Videos
[user1@pc1 ~]$ cd Year
[user1@pc1 Year]$ ls
Month
[user1@pc1 Year]$ cd Month
[user1@pc1 Month]$ cd -
/home/user1/Year
[user1@pc1 Year]$ cd Month
[user1@pc1 Month]$ cd ../..
[user1@pc1 ~]$ pwd
/home/user1
[user1@pc1 ~]$ cd Year/Month
[user1@pc1 Month]$ pwd
/home/user1/Year/Month
[user1@pc1 Month]$
In above example Year/Month folder was already created.
cp - To create a copy of file or folder
Syntax: cp <OldFile> <NewFile>
| Command | Description |
|---|---|
| cp File1 File1-Copy | Creates a copy of File1 and the new File name will be File1-Copy |
[user1@pc1 Folder1]$ ls
File1
[user1@pc1 Folder1]$ cp File1 File1-Copy
[user1@pc1 Folder1]$ ls
File1 File1-Copy
[user1@pc1 Folder1]$
mv - This command can be used for both rename and move file and folder
Syntax (rename): mv <OldFileName> <NewFileName>
Syntax (move): mv <File> <Foler>
| Command | Description |
|---|---|
| mv Flie1 File1 | To rename Flie1 to File1 |
| mv Flie1 Folder1/Folder2 | To move File1 from current location to Folder1/Folder2 |
[user1@localhost ~]$ ls
Desktop Downloads Folder1 Pictures Templates
Documents Flie1 Music Public Videos
[user1@localhost ~]$ mv Flie1 File1
[user1@localhost ~]$ ls
Desktop Downloads Folder1 Pictures Templates
Documents File1 Music Public Videos
[user1@localhost ~]$ ls Folder1/Folder2
[user1@localhost ~]$ mv File1 Folder1/Folder2
[user1@localhost ~]$ ls Folder1/Folder2
File1
[user1@localhost ~]$
rm - To remove file and with -r it removes folder.
Syntax (for File): rm <FileName>
Syntax (for Folder): rm -r <FolderName>
| Command | Description |
|---|---|
| rm File1 | To remove/delete File1 |
| rm -r Folder1 | To remove/delete Folder1 (and its subfolders and files if exist) |
[user1@localhost ~]$ cd Folder
[user1@localhost Folder]$ mkdir Folder{1,2,3}
[user1@localhost Folder]$ ls
Folder1 Folder2 Folder3
[user1@localhost Folder]$ touch Folder1/file1
[user1@localhost Folder]$ touch Folder{2,3}/file{2,3}
[user1@localhost Folder]$ ls -R
.:
Folder1 Folder2 Folder3
./Folder1:
file1
./Folder2:
file2 file3
./Folder3:
file2 file3
[user1@localhost Folder]$ ls
Folder1 Folder2 Folder3
[user1@localhost Folder]$ rm -r Folder1
[user1@localhost Folder]$ ls -R
.:
Folder2 Folder3
./Folder2:
file2 file3
./Folder3:
file2 file3
[user1@localhost Folder]$ rm -r Folder*
[user1@localhost Folder]$ ls
[user1@localhost Folder]$