Working with files and directories is a fundamental aspect of managing a CentOS system. Here are some common tasks you might perform:
1. Navigating the File System:
- Use the
cdcommand to change directories. For example:cd /path/to/directory - Use the
pwdcommand to print the current working directory.
2. Listing Files and Directories:
- Use the
lscommand to list files and directories in the current directory. For example:ls - Use options like
-lfor a detailed list,-ato show hidden files, and-hfor human-readable file sizes.
3. Creating Files and Directories:
- Use the
touchcommand to create an empty file. For example:touch filename - Use the
mkdircommand to create a new directory. For example:mkdir directoryname
4. Copying, Moving, and Renaming Files:
- Use the
cpcommand to copy files. For example:cp sourcefile destination - Use the
mvcommand to move or rename files. For example:mv oldname newname
5. Removing Files and Directories:
- Use the
rmcommand to remove files. For example:rm filename - Use the
rmdircommand to remove empty directories. For example:rmdir directoryname - Use the
rm -rcommand to remove directories and their contents recursively. Be cautious with this command, as it can delete files and directories permanently.
6. Viewing File Contents:
- Use the
catcommand to display the contents of a file. For example:cat filename - Use the
lesscommand to view long files one page at a time. For example:less filename
7. Editing Files:
- Use text editors like
nano,vim, oremacsto edit files. For example:
This will open the file in thenano filenamenanotext editor, where you can make changes and save them.
8. Searching for Files:
- Use the
findcommand to search for files and directories based on various criteria. For example:find /path/to/search -name "filename" - Use the
grepcommand to search within files for specific patterns. For example:grep "pattern" filename
9. Changing File Permissions and Ownership:
- Use the
chmodcommand to change file permissions. For example:chmod u+x filename - Use the
chowncommand to change file ownership. For example:chown username:groupname filename

Comments