These are the foundational commands for navigating and managing the file system.
ls
: Lists files and directories. ls -l
shows a long-format list with permissions.
ls -la
to show all files, including hidden ones, in a long list.cd
: Changes the current directory. cd ..
moves up one level. cd ~
goes to the home directory.
cd /var/www/html
to navigate to a web server's root directory.pwd
: Prints the full path of the current working directory.
pwd
will output something like /home/user/documents
.mkdir
: Creates a new directory.
mkdir -p projects/new_project
creates a directory and its parent directory if they don't exist.rmdir
: Removes an empty directory.
rmdir old_folder
.touch
: Creates a new, empty file or updates the timestamp of an existing file.
touch report.txt
.cp
: Copies files or directories.
cp -r /source/dir /destination/
copies a directory recursively.mv
: Moves or renames a file or directory.
mv old_file.txt new_file.txt
.rm
: Removes (deletes) files or directories. rm -rf
is a powerful and dangerous command to force-delete a directory and its contents recursively.
rm config.conf
.find
: Searches for files in a directory hierarchy.
find . -name "*.log"
finds all files ending with .log
in the current directory.These commands are for viewing and modifying the content of files.
cat
: Concatenates and displays file content. It's often used to quickly view small files.
cat file1.txt file2.txt > combined.txt
.less
: A file pager that lets you view file content one screen at a time, allowing you to scroll both up and down.
less big_log_file.log
.more
: Similar to less
, but with more limited scrolling functionality (typically only scrolls forward).
more README.md
.head
: Displays the first 10 lines of a file by default.
head -n 5 data.csv
to see the first 5 lines.