File Managements Commands
File Managements Commands
commands
df=> means disk free it's used to print the used and the available size
du => means disk used -it's use to print the disk used by file and display where they are located
at
diff => it compares two file and determine their size, that is compare files line by line
e.g. your 1st needs to have two files to be able to compare them, if you don’t have a file to
compare to you can create one for this test.
cat => can also be used to create a content(texts) to a file by using cat > filename
notice when you want to append(update) the previous file you should make use of the cat ">>"
instead of the ">" command they will overwrite what you have in the file already
e.g cat >>exercise. to append to an old file when done appending(writing) use ctrl + D to save
your file
you can verify the file written using ‘cat filename’ to display the content in the file
e.g. cp myfile ~/Documents/ this copies the file from the current folder or directory to another
which is the Documents directory of the home.
locate => is just like the find command that let's you locate a file, it goes through the system to
grab and output the files locations
locate ivona.conf
Basic File Commands
- List Files: ls - list files in a directory. Use ls -l for detailed listing and ls -a to include hidden files.
- Copy Files: cp - copy files and directories. Use cp -r to copy directories recursively.
- Remove Files: rm - delete files and directories. Use rm -r to delete directories recursively and
rm -f to force deletion.
Directory Operations
- Change Directory: cd - navigate between directories. Use cd .. to move up a directory and cd ~
to return to the home directory.
- Make Directory: mkdir - create new directories. Use mkdir -p to create parent directories if
they don't exist.
- View Text Files: less or more - view text files page by page.
- Head and Tail: head and tail - display the beginning or end of a file.
To delete a directory that's not empty in Linux, use the rm command with the -r option, which
stands for recursive removal. This will delete the directory and all its contents, including
subdirectories and files. Here's how to do it:
- Force Deletion: rm -rf directory_name (use with caution, as it won't prompt for confirmation)
- Interactive Mode: rm -ri directory_name (prompts for confirmation before deleting each file or
subdirectory)
Safety Precautions:
- Be cautious when using rm -rf, especially with system directories or important files.
- Double-check the directory path and contents before deletion to avoid accidental data loss.
- Consider using rm -ri for interactive deletion, which prompts for confirmation before deleting
each file or subdirectory.¹
Alternative Methods:
- Using a File Manager: You can also delete directories using a file manager like Nautilus in
Ubuntu. Simply select the directory and press Delete or right-click and choose "Move to Trash".
- Checking File System: If you encounter issues, try running fsck (File System Consistency Check)
to resolve file system errors.²