ls
- List Directory Contentsls
- the ls
command is used to list the files and directories in the current directory (you can also use the -l
flag to show more detailed information, and the -a
flag to show hidden files too)
Example of ls
being used
[root@zenith ~]# ls
anaconda-ks.cfg exec_recipe.log helloworld recipe_-1.log recipe_-208.log recipe_-423.log recipe_-569.log
Example of ls
with -l
and -a
flags
[root@zenith ~]# ls -la
total 68
dr-xr-x---. 3 root root 4096 Sep 23 10:52 .
dr-xr-xr-x. 19 root root 4096 Sep 20 13:33 ..
-rw-------. 1 root root 367 Sep 23 17:12 .bash_history
-rw-r--r--. 1 root root 18 May 11 2022 .bash_logout
-rw-r--r--. 1 root root 141 May 11 2022 .bash_profile
-rw-r--r--. 1 root root 429 May 11 2022 .bashrc
-rw-r--r--. 1 root root 100 May 11 2022 .cshrc
-rw------- 1 root root 20 Sep 23 10:52 .lesshst
drwx------ 2 root root 4096 Sep 20 12:16 .ssh
-rw-r--r--. 1 root root 129 May 11 2022 .tcshrc
-rw------- 1 root root 947 Sep 20 13:23 .viminfo
-rw-------. 1 root root 887 Jan 6 2023 anaconda-ks.cfg
-rw-r--r-- 1 root root 79 Sep 20 13:17 exec_recipe.log
-rw-r--r-- 1 root root 20 Sep 20 13:23 helloworld
-rw-r--r-- 1 root root 0 Sep 20 13:17 recipe_-1.log
-rw-r--r-- 1 root root 867 Dec 6 2023 recipe_-208.log
-rw-r--r-- 1 root root 907 Sep 20 13:17 recipe_-423.log
-rw-r--r-- 1 root root 51 Sep 20 13:17 recipe_-569.log
cd
- Change DirectoryThe cd
command can be used to navigate between different directories on the file system.
For example, if you're in /home/zarro/
and want to go to the 'Documents' folder, you can type cd Documents
Tip: Use the ~
symbol to return to your home folder. Example: cd ~
pwd
- Print Working DirectoryThe pwd
command can be used to display the full path of the current directory that you're in.
Example of pwd
:
[root@zenith audit]# pwd
/var/log/audit
mv
- Move or Rename Files/DirectoriesThe mv command is primarily used to move files from one location to another, but can also be used to rename a file.
Example moving a file:
[root@zenith ~]# mv helloworld kbarticle/
[root@zenith ~]# ls kbarticle/
helloworld
In this example, we have moved the 'helloworld
' file from the Root user directory to the 'kbarticle
' folder. We can then verify this by listing the directory contents of 'kbarticle/
'
Example renaming a file:
[root@zenith kbarticle]# mv helloworld helloworld2
[root@zenith kbarticle]# ls
helloworld2
In this example, we have renamed the file 'helloworld
' to 'helloworld2
'. We can verify that this has happened by listing out the directory contents to see the new file name.