Bash
File commands
Basic Bash file commands for listing, reading, and removing files.
Simple Bash commands for checking what is in a folder, reading file contents, and deleting files or folders.
List files with ls
#
ls lists the files and folders in the current directory.
lsYou can also point it at a specific path:
ls some-folderUse this when you want to quickly see what is inside a folder.
Read file contents with cat
#
cat prints file contents to the terminal.
cat some-file.mdUse this when you want to quickly read a small file without opening an editor.
Remove files with rm
#
rm removes files.
rm old-file.txtBe careful: this deletes the file instead of moving it to a recycle bin.
What -f means
#
-f means force.
rm -f old-file.txtThis tells rm:
- do not ask for confirmation
- do not complain if the file does not exist
Use it when you want rm to stay quiet and just try the deletion.
What -r means
#
-r means recursive.
rm -r old-folderThis tells rm to remove a folder and everything inside it.
What -rf means
#
-rf combines both flags:
-r= recursive-f= force
rm -rf old-folderThis removes the folder and everything inside it without asking.
Use rm -rf carefully, because it can delete a lot very quickly.