Basic Linux commands and file system navigation
- cd - change directory: This command is used to change the current working directory to another directory.
cd /home/user1/
This will change the current directory to "/home/user1/"
- ls - list directory contents: This command is used to list the files and directories in the current directory.
ls
This will display a list of files and directories in the current directory.
- mkdir - make directory: This command is used to create a new directory.
mkdir newdirectory
This will create a new directory named "newdirectory" in the current directory.
- touch - create an empty file: This command is used to create a new empty file.
touch newfile.txt
This will create a new file named "newfile.txt" in the current directory.
- cp - copy a file or directory: This command is used to copy a file or directory from one location to another.
cp file1.txt /home/user1/
This will copy the file "file1.txt" to the directory "/home/user1/"
- mv - move or rename a file or directory: This command is used to move a file or directory from one location to another, or to rename a file or directory.
mv file1.txt /home/user1/
This will move the file "file1.txt" to the directory "/home/user1/"
mv file1.txt file2.txt
This will rename the file "file1.txt" to "file2.txt"
- rm - remove a file or directory: This command is used to delete a file or directory.
rm file1.txt
This will delete the file "file1.txt"
rm -r directory1
This will delete the directory "directory1" and all its contents.
- pwd - print working directory: This command is used to display the current working directory.
pwd
This will display the current working directory.
- cat - concatenate and display files: This command is used to display the contents of one or more files.
cat file1.txt
This will display the contents of the file "file1.txt".
- head - display the first lines of a file: This command is used to display the first few lines of a file.
head file1.txt
This will display the first few lines of the file "file1.txt".
- tail - display the last lines of a file: This command is used to display the last few lines of a file.
tail file1.txt
This will display the last few lines of the file "file1.txt".
- grep - search for a pattern in a file: This command is used to search for a specific pattern or string in a file.
grep "pattern" file1.txt
This will search for the string "pattern" in the file "file1.txt".
- find - search for files and directories: This command is used to search for files and directories in a specific directory.
find /home/user1/ -name "file1.txt"
This will search for the file "file1.txt" in the directory "/home/user1/".
- tar - create or extract a compressed archive: This command is used to create or extract a compressed archive.
tar -cvf archive.tar file1.txt file2.txt
This will create a compressed archive named "archive.tar" containing the files "file1.txt" and "file2.txt".
tar -xvf archive.tar
This will extract the files from the archive "archive.tar".
- zip - compress or extract files: This command is used to compress or extract files.
zip archive.zip file1.txt file2.txt
This will create a compressed archive named "archive.zip" containing the files "file1.txt" and "file2.txt".
unzip archive.zip
This will extract the files from the archive "archive.zip".
- chmod - change file permissions: This command is used to change the permissions of a file or directory.
chmod 755 file1.txt
This will set the permissions of the file "file1.txt" to 755.
- chown - change file ownership: This command is used to change the ownership of a file or directory.
chown user1:group1 file1.txt
This will change the ownership of the file "file1.txt" to user1 and group1.
- ssh - remote login: This command is used to log in to a remote server.
ssh user1@192.168.0.1
This will log in to the server at IP address 192.168.0.1 as user1.
- scp - copy files between hosts: This command is used to copy files between two remote hosts.
scp file1.txt user1@192.168.0.1:/home/user1/
This will copy the file "file1.txt" to the directory "/home/user1/" on the remote server at IP address 192.168.0.1.
- ps - list running processes: This command is used to list the running processes on a system.
ps -ef
This will display a list of all running processes on the system.
- kill - terminate a process: This command is used to terminate a running process.
kill PID
This will terminate the process with the specified PID (process ID).
- df - display free disk space: This command is used to display the amount of free disk space on a system.
df -h
This will display the amount of free disk space on the system in a human-readable format.
- du - display disk usage: This command is used to display the disk usage of a file or directory.
du -h file1.txt
This will display the disk usage of the file "file1.txt" in a human-readable format.
- top - display system resources: This command is used to display real-time information about system resources, such as CPU and memory usage.
top
This will display real-time information about system resources in a terminal window.
- ps aux - list running processes: This command is used to list the running processes on a system.
ps aux
This will display a list of all running processes on the system.
- netstat - display network connections: This command is used to display the network connections on a system.
netstat -a
This will display a list of all network connections on the system.
- ping - test network connectivity: This command is used to test network connectivity.
ping 192.168.0.1
This will send ICMP packets to the IP address 192.168.0.1 to test network connectivity.
- ifconfig - configure network interfaces: This command is used to configure network interfaces.
ifconfig eth0 192.168.0.2 netmask 255.255.255.0
This will configure the network interface eth0 with the IP address 192.168.0.2 and netmask 255.255.255.0.
- iwconfig - configure wireless network interfaces: This command is used to configure wireless network interfaces.
iwconfig wlan0 essid "MyWiFi" key s:password
This will configure the wireless network interface wlan0 to connect to the network "MyWiFi" with the password "password".
- route - display or configure the network routing table: This command is used to display or configure the network routing table.
route -n
This will display the network routing table.
- traceroute - trace the route to a network host: This command is used to trace the route to a network host.
traceroute google.com
This will trace the route to the network host google.com.
- wget - download files from the internet: This command is used to download files from the internet.
wget https://example.com/file1.txt
This will download the file "file1.txt" from the website "example.com".
- curl - transfer data from or to a server: This command is used to transfer data from or to a server.
curl -o file1.txt https://example.com/file1.txt
This will download the file "file1.txt" from the website "example.com" and save it as "file1.txt".
- ssh-keygen - generate SSH keys: This command is used to generate SSH keys.
ssh-keygen -t rsa -b 4096
This will generate a new RSA key pair
- ssh - connect to a remote server using SSH: This command is used to connect to a remote server using SSH.
ssh user@remote_host
This will establish an SSH connection to the remote host using the specified username.
- scp - copy files between hosts using SSH: This command is used to copy files between hosts using SSH.
scp file1.txt user@remote_host:/home/user/
This will copy the file "file1.txt" to the remote host's "/home/user/" directory using SSH.
- rsync - synchronize files between hosts: This command is used to synchronize files between hosts.
rsync -avz /local/path user@remote_host:/remote/path
This will synchronize the files from the local "/local/path" directory to the remote "/remote/path" directory using rsync.
- tar - create and extract tar archives: This command is used to create and extract tar archives.
tar -cvf archive.tar file1.txt file2.txt
This will create a new tar archive called "archive.tar" containing "file1.txt" and "file2.txt".
tar -xvf archive.tar
This will extract the contents of the tar archive "archive.tar".
- gzip and gunzip - compress and decompress files: These commands are used to compress and decompress files.
gzip file1.txt
This will compress the file "file1.txt".
gunzip file1.txt.gz
This will decompress the file "file1.txt.gz".
- chown - change the ownership of a file or directory: This command is used to change the ownership of a file or directory.
chown user:group file1.txt
This will change the owner of the file "file1.txt" to the specified user and group.
- chmod - change the permissions of a file or directory: This command is used to change the permissions of a file or directory.
chmod 644 file1.txt
This will change the permissions of the file "file1.txt" to read and write for the owner and read-only for everyone else.
- find - search for files or directories: This command is used to search for files or directories.
find / -name file1.txt
This will search for the file "file1.txt" in the entire file system.
- grep - search for a pattern in a file: This command is used to search for a pattern in a file.
grep "pattern" file1.txt
This will search for the specified pattern in the file "file1.txt".
- sed - search and replace text in a file: This command is used to search and replace text in a file.
sed -i 's/old_text/new_text/g' file1.txt
This will replace all instances of "old_text" with "new_text" in the file "file1.txt".
- awk - manipulate and analyze text files: This command is used to manipulate and analyze text files.
awk '{print $1, $2}' file1.txt
This will print the first two columns of the file "file1.txt".
- tail - display the last few lines of a file: This command is used to display the last few lines of a file.
tail file1.txt
This will display the last 10 lines of the file
- head - display the first few lines of a file: This command is used to display the first few lines of a file.
head file1.txt
This will display the first 10 lines of the file "file1.txt".
- tee - redirect output to a file and the terminal: This command is used to redirect output to a file and the terminal.
ls | tee file1.txt
This will list the files in the current directory and save the output to the file "file1.txt" and also display the output on the terminal.
- cut - extract columns from a file: This command is used to extract columns from a file.
cut -d "," -f 1,2 file1.txt
This will extract the first two columns of the file "file1.txt" using the comma as the delimiter.
- paste - merge lines from multiple files: This command is used to merge lines from multiple files.
paste file1.txt file2.txt
This will merge the lines from the two files "file1.txt" and "file2.txt".
- sort - sort lines in a file: This command is used to sort lines in a file.
sort file1.txt
This will sort the lines in the file "file1.txt" in ascending order.
- uniq - remove duplicate lines from a file: This command is used to remove duplicate lines from a file.
uniq file1.txt
This will remove any duplicate lines in the file "file1.txt".
- wc - count lines, words, and characters in a file: This command is used to count the number of lines, words, and characters in a file.
wc file1.txt
This will display the number of lines, words, and characters in the file "file1.txt".
- df - display disk space usage: This command is used to display the disk space usage.
df -h
This will display the disk space usage in a human-readable format.
- du - display the size of a file or directory: This command is used to display the size of a file or directory.
du -sh /home/user/
This will display the size of the "/home/user/" directory in a human-readable format.
- top - display system processes and resource usage: This command is used to display system processes and resource usage.
top
This will display the system processes and their resource usage in real-time.
- ps - display running processes: This command is used to display the running processes.
ps
This will display the currently running processes.
- kill - send a signal to a process: This command is used to send a signal to a process.
kill PID
This will send a signal to the process with the specified process ID (PID).
- ping - test network connectivity: This command is used to test network connectivity.
ping google.com
This will test the network connectivity to "google.com".
- traceroute - trace the network path to a host: This command is used to trace the network path to a host.
traceroute google.com
This will trace the network path to "google.com".
- nslookup - query DNS information: This command is used to query DNS information.
nslookup google.com
This will query the DNS information for "google.com".
- dig - DNS lookup utility: This command is used to perform DNS lookups.
dig google.com
This will perform a DNS lookup for "google.com".
- ssh - secure shell client: This command is used to connect to a remote system using the secure shell (SSH) protocol.
ssh user@remote_host
This will connect to the remote system with the username "user" at the hostname "remote_host".
- scp - secure copy: This command is used to copy files between systems using the secure copy (SCP) protocol.
scp file.txt user@remote_host:/path/to/destination
This will copy the file "file.txt" to the remote system at the specified destination.
- rsync - remote file sync: This command is used to synchronize files between systems.
rsync -avz /path/to/source user@remote_host:/path/to/destination
This will synchronize the files from the local system to the remote system.
- tar - archive files: This command is used to create an archive of one or more files.
tar -cvf archive.tar file1.txt file2.txt
This will create an archive called "archive.tar" containing the files "file1.txt" and "file2.txt".
- gzip - compress files: This command is used to compress files.
gzip file1.txt
This will compress the file "file1.txt" and create a new file called "file1.txt.gz".
- gunzip - uncompress files: This command is used to uncompress files.
gunzip file1.txt.gz
This will uncompress the file "file1.txt.gz" and create a new file called "file1.txt".
- curl - transfer data from or to a server: This command is used to transfer data from or to a server.
curl https://example.com
This will retrieve the content of the specified URL.
- wget - download files from the internet: This command is used to download files from the internet.
wget https://example.com/file.txt
This will download the file "file.txt" from the specified URL.
- history - display command history: This command is used to display the command history.
history
This will display the command history of the current session.
- alias - create an alias for a command: This command is used to create an alias for a command.
alias ll='ls -l'
This will create an alias "ll" for the "ls -l" command.
Leave a Comment