Common commands for working with directories in Linux

Source: Internet
Author: User

let's look at a few common commands for working with directories:

LS: List directory

CD: Switch directories

pwd: Displays the current directory

mkdir: Create a new directory

RmDir: Delete an empty directory

CP: Copying Files or directories

RM: Remove files or directories

MV (move files and directories, or modify names)


You can use the man [command] to view the documentation for each command, such as: Man CP.


ls (list directory)

Options and Parameters:

- A: All files are listed together with the hidden file (files that begin with.) (common)

-D: Lists only the directory itself, not the file data in the directory (common)

-L: Long data string list, including file attributes and permissions and so on data; (common)


<span style= "FONT-SIZE:14PX;"            >[email protected]:~$ lsdump examples.desktop Public video document music Erh-mongo-munin-08e7aeb tech163 Template picture Download Desktop [email protected]:~$ ls-l total dosage 56drwxrwxr-x 6 Deng Deng 4096 June 9 17:56 dumpdrwxrwxr-x 3 Deng Deng 4096 February erh-mongo-munin-08e7aeb-rw-r--r--1 Deng Deng 8445 June 6 09:21 examples.desktopdrwxrwxr-x 3 D Eng Deng 4096 June 08:35 tech163drwxr-xr-x 2 Deng Deng 4096 June 6 11:19 public drwxr-xr-x 2 Deng Deng 4096 June 6 11:19 template D Rwxr-xr-x 2 Deng Deng 4096 June 6 11:19 video Drwxr-xr-x 2 Deng Deng 4096 June 6 11:19 picture Drwxr-xr-x 5 Deng Deng 4096 June 9 17 : 25 Document Drwxr-xr-x 3 Deng Deng 4096 June 11 09:51 Download Drwxr-xr-x 2 Deng Deng 4096 June 6 11:19 Music drwxr-xr-x 2 Deng Deng 4096 6                        Month 11 10:23 Desktop [email protected]:~$ ls-a.                       . Gksu.lock. Rpmdb.            . gnome2. Sunpinyin.adobe. GOUTPUTSTREAM-0D97ZX tech163.bash_history. goutputstream-syqvzx. thumbnails.bash_logout. goutputstream-xwfpzx. VIMINFO.BASHRC. Gstrea mer-0.10. Xauthority.cache. Gtk-bookmarks. xinputrc.compiz-1. Gvfs. Xsessi On-errors.config. Iceauthority. Xsession-errors.old.dbshell. java public. Dbus. Loc Al template. dmrc. Macromedia Video dump. Mission-control Pictures E              Rh-mongo-munin-08e7aeb. Mozilla document examples.desktop. PIP download. fontconfig . Profile music. Freemind. Pulse Desktop. gconf. pulse-cookie</sp An>
CD (switch directory)
<span style= "FONT-SIZE:14PX;" > CD [relative path or absolute path]</span>

<span style= "FONT-SIZE:14PX;" >[email protected]:~$ mkdir jingdong[email protected]:~$ CD jingdong[email protected]:~/jingdong$ CD. #返回上一层文件夹 [email protected]:~$ cd/home/deng/tech163[email protected]:~/tech163$ cd-#相当于文档中的Ctrl +z, rollback/home/deng[ Email protected]:~$ cd/#返回根目录 </span>

pwd (Displays the directory that is currently located)options and Parameters:-P: shows the exact path, not the link path.

mkdir (Create new directory)
<span style= "FONT-SIZE:14PX;" >mkdir [-MP] Directory name </span>

Options and Parameters:
-M: Configuration file Permissions Oh! Direct configuration, do not need to see the default permissions (umask) face ~
-P: help you to directly create the desired directory (including the top level directory) back up!


rmdir (Delete empty directory)Options and Parameters:
-P: Along with the previous level of "empty" directories are also deleted


cp (copy files or directories)
<span style= "FONT-SIZE:14PX;" >CP [-adfilprsu] source file (source) target file (destination) CP [options] Source1 source2 source3 .... directory</span>

Options and Parameters:
-A: As-pdr means, please refer to the following instructions for PDR. (common)
-D: If the source file is the attribute of the link file, the link file property is copied instead of the file itself;
-F: For force, if the target file already exists and cannot be opened, then try again after removing it;
-I: If the target file (destination) already exists, the action will be asked (commonly used) when overwriting
-L: Create a link file for a hard link, rather than copying the file itself;
-P: Copy the past along with the properties of the file, rather than using the default properties (backup is often used);
-R: Recursive continuous replication, used for the replication behavior of the directory; (Common)
-S: Copy becomes the symbolic link file (symbolic link), i.e. "shortcut" files;
-U: Upgrade destination If destination is older than source!


rm (remove files or directories)
<span style= "FONT-SIZE:14PX;" >RM [-fir] file or directory </span>

Options and Parameters:
-F: Is the meaning of force, ignoring the nonexistent file, no warning message appears;
-I: Interactive mode that asks the user whether or not to move before deleting
-R: Pass it back! Most commonly used in directories are deleted! This is a very dangerous option!!!


MV (move files and directories, or modify names)
<span style= "FONT-SIZE:14PX;" >MV [-fiu] Source DESTINATIONMV [options] source1 source2 source3 .... directory</span>

Options and Parameters:
-f:force mandatory Meaning, if the target file already exists, will not be asked and directly covered;
-I: If the target file (destination) already exists, you will be asked to overwrite it!
-U: If the target file already exists and source is newer, it will be upgraded (update)

Common commands for working with directories in Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.