To study and execute basic UNIX commands.
Linux operating system.
Syntax:
ls [options] [directory]
Code:
ls -l /home/user
Output:
List of files and directories in /home/user with details.
Syntax:
cd [directory]
Code:
cd /var/www
Output:
Change to the /var/www directory.
Syntax:
pwd
Code:
pwd
Output:
/home/user (prints the current working directory).
Syntax:
mkdir [directory]
Code:
mkdir my_directory
Output:
Creates a new directory named my_directory.
Syntax:
touch [filename]
Code:
touch newfile.txt
Output:
Creates a new empty file named newfile.txt.
Syntax:
cp [options] source destination
Code:
cp file.txt /backup/
Output:
Copies file.txt to the /backup/ directory.
Syntax:
mv [options] source destination
Code:
mv oldfile.txt newfile.txt
Output:
Renames oldfile.txt to newfile.txt.
Syntax:
rm [options] [file/directory]
Code:
rm file.txt
Output:
Deletes file.txt.
Syntax:
cat [filename]
Code:
cat file.txt
Output:
Displays the content of file.txt.
Syntax:
more [filename]
Code:
more longfile.txt
Output:
Allows you to view the content of longfile.txt one page at a time.
Syntax:
less [filename]
Code:
less largefile.txt
Output:
Displays largefile.txt with navigation capabilities.
Syntax:
head [options] [filename]
Code:
head -n 5 file.txt
Output:
Shows the first 5 lines of file.txt.
Syntax:
tail [options] [filename]
Code:
tail -n 10 file.log
Output:
Shows the last 10 lines of file.log.
Syntax:
grep [options] 'pattern' [file(s)]
Code:
grep 'keyword' file.txt
Output:
Lists lines containing 'keyword' in file.txt.
Syntax:
find [path] [expression]
Code:
find /home/user -name '*.txt'
Output:
Finds all .txt files under /home/user.
Syntax:
chmod [options] permissions file(s)
Code:
chmod 644 file.txt
Output:
Sets read and write permissions for the owner and read-only permissions for others on file.txt.
Syntax:
chown [options] user:group file(s)
Code:
chown user:group file.txt
Output:
Changes the owner and group of file.txt.
Syntax:
tar [options] [file(s)]
Code:
tar -cvzf archive.tar.gz dir/
Output:
Creates a compressed archive of the dir/ directory.
Syntax:
df [options] [filesystem(s)]
Code:
df -h
Output:
Shows disk space usage in a human-readable format.
Syntax:
du [options] [directory]
Code:
du -sh /var
Output:
Displays the total size of the /var directory in a human-readable format.
Syntax:
ps [options]
Code:
ps aux
Output:
Lists running processes with details.
Syntax:
kill [signal] [PID]
Code:
kill -9 1234
Output:
Sends a SIGKILL signal to process with PID 1234.
Syntax:
ssh [user@]hostname
Code:
ssh user@remote-server
Output:
Establishes a secure remote connection to remote-server.
Syntax:
scp [options] source destination
Code:
scp file.txt user@remote-server:/path/
Output:
Copies file.txt to a remote server over SSH.
Syntax:
wget [options] [URL]
Code:
wget https://example.com/file.zip
Output:
Downloads file.zip from the specified URL.
Thus basic UNIX commands are studied and executed.