Managing Files and Directories with Linux CLI
The Linux command-line interface (CLI) provides a rich set of tools and utilities for managing files and directories. These tools allow users to perform a wide range of file management tasks, from basic operations like creating, copying, and deleting files, to more advanced tasks like searching, sorting, and manipulating file contents.
Navigating the File System
The cd
(change directory) command is used to navigate the file system. For example, to change the current working directory to the /home/user/documents
directory, you would use the following command:
cd /home/user/documents
You can also use relative paths to navigate the file system. For example, if you are currently in the /home/user
directory and you want to navigate to the documents
subdirectory, you can use the following command:
cd documents
Listing Files and Directories
The ls
(list) command is used to display the contents of a directory. By default, ls
will list the files and directories in the current working directory. You can also use the ls
command to list the contents of a specific directory. For example:
ls /home/user/documents
The ls
command also supports various options, such as -l
to display detailed file information, and -a
to include hidden files and directories.
Creating and Deleting Files and Directories
The touch
command is used to create new files. For example, to create a new file named example.txt
in the current working directory, you would use the following command:
touch example.txt
The mkdir
command is used to create new directories. For example, to create a new directory named new_directory
in the current working directory, you would use the following command:
mkdir new_directory
To delete files and directories, you can use the rm
(remove) command. For example, to delete the example.txt
file, you would use the following command:
rm example.txt
To delete a directory and its contents, you can use the -r
(recursive) option with the rm
command. For example, to delete the new_directory
directory and its contents, you would use the following command:
rm -r new_directory
By mastering these basic file management commands, users can effectively navigate and manage files and directories in the Linux CLI, laying the foundation for more advanced file handling tasks.