Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

Directory Commands

  • pwd: Print the current working directory.

pwd

  • ls: List directory contents.

ls
ls -l  # Long listing format
ls -a  # Include hidden files
ls -lh # Human-readable format

  • cd [directory]: Change the current directory.

cd /path/to/directory
cd ..   # Move up one directory
cd ~    # Change to home directory
cd -    # Change to the previous directory

  • mkdir [directory]: Create a new directory.

mkdir new_directory
mkdir -p /path/to/new_directory  # Create parent directories as needed

  • rmdir [directory]: Remove an empty directory.

rmdir empty_directory

  • rm -r [directory]: Remove a directory and its contents recursively.

rm -r directory_name

File Commands

  • touch [file]: Create an empty file or update the timestamp of an existing file.

touch new_file.txt

  • cp [source] [destination]: Copy files or directories.

cp file1.txt /path/to/destination/
cp -r /path/to/source_directory /path/to/destination_directory

  • mv [source] [destination]: Move or rename files or directories.

mv file1.txt /path/to/destination/ #  The directory where you want to move the file
mv old_name.txt new_name.txt      # rename a text file
mv job23.sh job45.sh              # rename a job script

  • rm [file]: Remove files or directories.

rm file1.txt
rm -r directory_name  # Remove a directory and its contents
rm -f file1.txt       # Force remove without prompting

  • cat [file]: Concatenate and display file content.

cat file1.txt
cat -E job.sh # display a $ at the end of each line, which can help visualize extra spacing
cat -n file2.txt # -n option cat displays line numbers
cat -v foo.txt # -v: Display non-printing characters, except for tabs and end-of-line characters.
cat -T foo.txt # -T: Show tab characters as ^I.

  • more [file]: View file content one screen at a time.

more file1.txt

  • less [file]: View file content with backward and forward navigation.

less file1.txt

  • head [file]: Display the first few lines of a file.

head file1.txt
head -n 20 file1.txt  # Display the first 20 lines

  • tail [file]: Display the last few lines of a file.

tail file1.txt
tail -n 20 file1.txt  # Display the last 20 lines

  • No labels