Linux Shell: File directory Operations and instances

Source: Internet
Author: User
Tags create directory parent directory touch

This article describes the underlying file operations: Create, move, edit, delete files and folders


Command and Case:


mkdir Creating a Directory


--Create two directories

[Email protected]:~$ mkdir test2 test3


--Create a new directory under Test1 Mydir

[Email protected]:~$ mkdir Test1/mydir


--Try to create a new directory under test100 Mydir, but not successful because test100 this directory does not exist

[Email protected]:~$ mkdir test100/mydir mkdir:cannot Create directory ' Test100/mydir ': No such file or directory


--Force the creation of two files for father and son, although test100 this parent directory does not exist

[Email protected]:~$ mkdir-p Test100/mydir


Touch Create File


--Create a hello file in the current directory

[Email protected]:~$ Touch Hello Echo


--write "Hello" to this directory

[Email protected]:~/test1$ cat Hellobackup[email protected]:~/test1$ echo "Hello" > hellobackup [email protected]:~/ test1$ Cat Hellobackuphello



MV Move or rename files


--Move the file hello to the Test1 folder

[Email protected]:~$ mv Hello Test1


--Rename file Hello to Hellobackup

[Email protected]:~/test1$ mv Hello Hellobackup


CP Copy File

[Email protected]:~$ cp pse2 test2--Copy file Pse2 to Test2 folder


Rm/rmdir deleting files and folders


--Delete File Hello

[Email protected]:~$ rm Hello


--Delete Folder Test2
[Email protected]:~$ rmdir test2


Input Redirect to file:


The following will write the input of the interface to the file Hellobackup file

[Email protected]:~$ cat <<eof >hellobackup> Hello world!> real func> EOF
Often read the contents of the file [email protected]:~$ cat Hellobackuphello world!real func[email protected]:~$


Complete example (create and delete files)

[Email protected]:~$ cd mhydir[email protected]:~/mhydir$ ls[email protected]:~/mhydir$ Touch test[email protected]:~/ mhydir$ lstest[email protected]:~/mhydir$ rm test[email protected]:~/mhydir$ ls[email protected]:~/mhydir$ Touch test[ Email protected]:~/mhydir$ rm-i Test--will Confirm Whether delete the Filerm:remove regular empty file ' test '? N[email protected]:~/mhydir$ lstest[email protected]:~/mhydir$ rm-i testrm:remove Regular empty file ' test '? Y[email protected]:~/mhydir$ Ls[email protected]:~/mhydir$


Linux Shell: File directory Operations and instances

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.