You can get the advice from IT HELP DESK

SYSTEM[LINUX] Commands about Directories

17 Jan 2019
<head>Disk Management, Server Monitoring, System management, server monitoring, server management, system management, system monitoring, </head>

[LINUX] Commands about Directories 

Hello ~!

This time, I will look at five common commands related to directories of Linux commands ~

1. Print working directory: pwd

Prints the current working directory or simply the directory user is, at present.

[root@localhost sbin]# pwd
[root@localhost sbin]#

2. List files and directories: ls 

An abbreviation for list segments, which displays files and folders within the folder to which they belong.

It is one of the most used commands and is often used with "-al" option.

[root@localhost usr]# pwd
[root@localhost usr]# ls -al
Total 116
drwxr-xr-x.  13 root root  4096 2018-12-20 12:31 .
dr-xr-xr-x.  25 root root  4096 2018-12-31 15:33 ..
dr-xr-xr-x.   2 root root 28672 2018-12-20 13:29 bin
drwxr-xr-x.   2 root root  4096 2011-09-23 20:50 etc
drwxr-xr-x.   2 root root  4096 2011-09-23 20:50 games
drwxr-xr-x.  35 root root  4096 2018-12-20 12:33 include
dr-xr-xr-x.  25 root root  4096 2018-12-20 12:33 lib
dr-xr-xr-x.  46 root root 28672 2018-12-20 13:28 lib64
drwxr-xr-x.  13 root root  4096 2018-12-20 13:29 libexec
drwxr-xr-x.  12 root root  4096 2018-12-20 12:31 local
dr-xr-xr-x.   2 root root 12288 2018-12-20 13:29 sbin
drwxr-xr-x. 109 root root  4096 2018-12-20 12:35 share
drwxr-xr-x.   4 root root  4096 2018-12-20 12:31 src
lrwxrwxrwx.   1 root root    10 2018-12-20 12:31 tmp -> ../var/tmp

※  Option:

  • ls -a: Show hidden files or directories  
  • ls -l:  Print details  
  • ls -S: Output in order of file size  
  • ls -r:  Sort in descending order (defaults to the ls command in ascending order)  
  • ls -R: Print to   sub-directories
  • ls -h: Convert the output capacity of basic BYTE    to the readable capacity (ex: 1K, 234M, 2G, etc.)

3. Move directory: cd 

It is an abbreviation of change directory. It is used to change the working directory to move to the desired directory.

The path can be an absolute path or a relative path.

[root@localhost usr]#pwd
[root@localhost usr]#cd local/
[root@localhost local]#pwd
[root@localhost local]#cd /etc/sysconfig/
[root@localhost sysconfig]#pwd
[root@localhost sysconfig]#

※  Option:

  • cd .: One point returns current directory  
  • cd ..: Two points return parent directory  
  • cd ~: Wave moves to the logged-in user's home directory  
  • cd ~ account name: Enter the wave and account name to go to the home directory of the specified account

4. Create directory: mkdir 

Make directory is an abbreviation for make directory.

[root@localhost usr]#mkdir test
[root@localhost usr]#ls
bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src  test  tmp

※  Option:  

  • mkdir -m: Set permissions when creating directories, defaults to 755  
  • mkdir -p: also creates a parent path 
  • mkdir -v: After creating the directory, print a message to the generated directory   

5. Remove directory: rmdir 

This is an abbreviation for remove directory, which is used to delete directories.

[root@localhost usr]#rmdir test  -- Delete test folder.
[root@localhost usr]#ls  -- to check that folder removed. 
bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src   tmp

※  Option:

  •   rmdir -p: Also delete the parent directory.