Commands for operating files and directories in Ubuntu

In Ubuntu, the operation commands of files and directories are very important. These commands help you create, copy, move, delete and view files and directories in the file system. The following are some common file and directory manipulation commands:

  1. cd

The cd command is used to change the current working directory.

For example, to change the working directory to the /home/user/Documents/ directory, use the following command:

cd /home/user/Documents/
  1. ls

The ls command is used to list the files and subdirectories under the specified directory.

For example, to list all files and subdirectories under the /home/user/Documents/ directory, the following command can be used:

ls /home/user/Documents/
  1. pwd

The pwd command is used to display the path of the current working directory.

For example, to display the path of the working directory you are currently in, you can use the following command:

pwd
  1. mkdir

The mkdir command is used to create new directories.

For example, to create a directory called new_directory in the current working directory, use the following command:

mkdir new_directory
  1. touch

The touch command is used to create new files or change the access and modification timestamps of existing files.

For example, to create a new file named myfile.txt in the current working directory, use the following command:

touch myfile.txt
  1. cp

The cp command is used to copy files and directories.

For example, to copy a file named file1 into a file named file2, use the following command:

cp file1 file2

To copy a directory named dir1 and all its subdirectories and files into a directory named dir2, you can use the following command:

cp -R dir1 dir2
  1. mv

The mv command is used to move and rename files and directories.

For example, to move a file named file1 into a file named file2, use the following command:

mv file1 file2

To move a directory named dir1 into a directory named dir2, you can use the following command:

mv dir1 dir2
  1. rm

The rm command is used to delete files and directories.

For example, to delete a file named file1 from the current working directory, the following command can be used:

rm file1

To delete a directory named dir1 and all its subdirectories and files from the current working directory, you can use the following command:

rm -r dir1
  1. cat

The cat command is used to view the contents of a file.

For example, to view the contents of a file named myfile.txt, use the following command:

cat myfile.txt

The above are some commonly used file and directory operation commands in Ubuntu. In addition to these commands, there are some other commands that can accomplish more tasks, such as chmod, chown, ln, etc. If you need to know about these commands, you can use the man command to view the man pages for the commands.

Guess you like

Origin blog.csdn.net/2302_77270563/article/details/129967112