File Management Commands ๐
ls
Description: Lists directory contents.
- Usage:
ls # Lists files and directories in the current directory
ls -l # Lists files with detailed information
ls -a # Lists all files including hidden files
cd
Description: Changes the current directory.
Usage:
cd /path/to/directory # Changes to the specified directory cd .. # Moves up one directory level cd ~ # Changes to the home directory
pwd
Description: Prints the current working directory.
Usage:
pwd # Displays the full path of the current directory
mkdir
Description: Creates a new directory.
Usage:
mkdir new_directory # Creates a new directory named 'new_directory' mkdir -p /path/to/new_dir # Creates a nested directory structure
rm
,rmdir
Description: Deletes files and directories.
Usage:
rm file_name # Deletes a file rm -r directory_name # Recursively deletes a directory and its contents rmdir directory_name # Deletes an empty directory
cp
Description: Copies files and directories.
Usage:
cp source_file destination_file # Copies a file
cp -r source_directory destination_directory # Copies a directory recursively
mv
Description: Moves or renames files and directories.
Usage:
mv old_name new_name # Renames a file or directory mv file_name /path/to/destination # Moves a file to a new location
touch
Description: Creates an empty file or updates the timestamp of an existing file.
Usage:
touch new_file # Creates an empty file named 'new_file' or updates its timestamp
ln
(hard link, soft link)Description: Creates hard and symbolic (soft) links.
Usage:
ln source_file link_name # Creates a hard link
ln -s source_file soft_link_name # Creates a symbolic link
Viewing and Editing Files ๐
cat
, zcat
Description: Concatenates and displays file content.
Usage:
cat file_name # Displays the content of a file zcat file_name.gz # Displays the content of a compressed file
head
Description: Outputs the first part of a file.
Usage:
head file_name # Displays the first 10 lines of a file head -n 5 file_name # Displays the first 5 lines of a file
tail
,tail -f
Description: Outputs the last part of a file.
Usage:
tail file_name # Displays the last 10 lines of a file tail -f file_name # Continuously monitors a file for new lines
less
,more
Description: Views file content one screen at a time.
Usage:
less file_name # Opens a file for viewing more file_name # Opens a file for viewing, but with fewer features than 'less'
vi
editorDescription: Opens the
vi
text editor.
Usage:
vi file_name # Opens a file in the `vi` editor
# In `vi`, use 'i' to enter insert mode, 'Esc' to exit insert mode, ':w' to save, and ':q' to quit
System Information and Management ๐ฅ๏ธ
ps
Description: Reports a snapshot of current processes.
Usage:
ps # Displays a snapshot of current processes ps aux # Displays detailed information about all running processes
top
Description: Displays real-time system information including processes.
Usage:
top # Starts the top command
df
Description: Reports file system disk space usage.
Usage:
df # Displays disk space usage for all mounted filesystems df -h # Displays disk space usage in human-readable format
du
Description: Estimates file and directory space usage.
Usage:
du directory_name # Displays the disk usage of a directory and its contents du -sh directory_name # Displays the disk usage in human-readable format
free
Description: Displays the amount of free and used memory in the system.
Usage:
free # Displays memory usage free -h # Displays memory usage in human-readable format
vmstat
Description: Reports virtual memory statistics.
Usage:
vmstat # Displays a summary of system performance
Networking Commands ๐
ssh
Description: Connects to a remote machine securely.
Usage:
ssh user@hostname # Connects to a remote machine ssh user@hostname -p port_number # Connects to a remote machine on a specific port
Process Management ๐ง
fuser
Description: Identifies processes using files or sockets.
Usage:
fuser file_name # Displays processes using the specified file
kill
Description: Sends a signal to a process, usually to terminate it.
Usage:
kill PID # Sends the default TERM signal to a process kill -9 PID # Forcefully terminates a process
nohup
Description: Runs a command immune to hangups, with output to a non-tty.
Usage:
nohup command & # Runs 'command' in the background, immune to hangups
Miscellaneous Commands ๐
cut
Description: Removes sections from each line of files.
Usage:
cut -d',' -f1 file_name # Cuts the first field from a comma-delimited file
tee
Description: Reads from standard input and writes to standard output and files.
Usage:
command | tee file_name # Writes the output of 'command' to 'file_name' and to the terminal
sort
Description: Sorts lines of text files.
Usage:
sort file_name # Sorts a file alphabetically sort -n file_name # Sorts a file numerically
clear
Description: Clears the terminal screen.
Usage:
clear # Clears the terminal
diff
Description: Compares files line by line.
Usage:
diff file1 file2 # Shows the differences between 'file1' and 'file2'
wc
Description: Word, line, character, and byte count for files.
Usage:
wc file_name # Displays line, word, and byte counts wc -l file_name # Displays line count