Q1.
Describe the basic commands of
Linux (as discussed in class).
Ans)
pwd -- displays the current working directory of terminal
echo -- writes argument to standard output
su -- switches to root
su username -- switches to other user
sudo -- executes only that command with root user privileges
whoami -- shows currently logged in user
passwd -- change password
cd / cd ~ -- change directory to home directory (use inverted
commas if folder name has space in it)
cd / -- changes to root directory
cd .. -- changes to parent directory
ls path -- list
ls -l -- lists permissions of all files (read, read-write, etc)
ls -a -- lists hidden content
ls --author -- lists author of contents
ls -S -- sorts according to size
ls *.extension -- lists only the particular extension
ls -LS > file.txt -- copies result into text file
cat path -- shows content of file
cat -b path -- numbers the non-blank lines
cat -n path -- adds numbers to all lines
cat -s path -- squeezes blank lines into one line
cat -E -- adds $ at the end of the line
cat > file.txt -- creates a text file and can enter text from the
terminal
cat >> file.txt -- can edit an existing file (ctrl+d to save & exit)
cp file1 file2 -- copy files & directories
cp -i -- interactive mode -> asks before overwriting
cp -n -- doesn't overwrite the file
cp -u -- updates destination file only when source file is
different from destination file
cp -R -- copies file to different directory
cp -v -- verbose; lists each file being processed
mv file1 file2: move
mv -i -- shows process (interactive)
mv -u -- if there's 2 files with the same name & if source file is
newer than destination file, then it'll be overwritten
mv -v -- shows the whole process
mkdir: make directory
mkdir -p/--parents -- makes nested directory
mkdir -p file1/{subdir1,subdir2,subdir3} -- creates nested
directories
rmdir foldername -- remove directory but needs to be EMPTY
rmdir -p -- removes parent & child directory
rmdir -pv -- does the same but shows each process (verbose)
rm -r -- removes even non-empty directories
rm -rp -- removes non-empty directories including parent and
child directories
who: detailed version of whoami
who -b -- latest boot time
who -q -- no of users and usernames
who -r -- current run level
uname -s -- kernel
uname-r -- kernel release version
uname -v -- kernel version
uname-m -- machine hardware names
uname-o -- os name
uname-a -- all of the above
touch -- creates empty files
head filename -- shows 1st 10 lines of a file
head -n number filename -- shows specific lines of the file
tail filename -- shows last 10 lines of a file
last -n number filename -- shows specific lines of the file
more filename -- shows the file
gzip filename -- to compress
Q2. Describe file system in Linux.
Ans) The Linux file system is a hierarchical structure starting
from the root directory (/). It includes various subdirectories
like /bin, /etc, and /home. Key features include support for
multiple file system types, inode-based metadata management,
mounting capabilities, and robust file permissions for security.
Q3. Describe file ownership and file
permissions. State the commands to
change ownership and permissions of a
file.
Ans) File ownership in Linux determines who can access and
modify files. Permissions are categorized as read, write, and
execute for user, group, and others. Use the chown command
to change ownership (sudo chown newuser filename) and
the chmod command to modify permissions (chmod 755
filename).
Q4. Explain archiving and compression
of files. State the appropriate
commands along with Proper syntax to
archive files (for example, file1, file2,
file3) into 'all.tar' file and compress the
archived file. Also, give the commands
for extracting the original files from this
compressed file.
Ans) Archiving and compression in Linux involve bundling
multiple files into a single file for easier management and
reducing storage space. The tar command is commonly used
for this purpose. To archive files (file1, file2, file3)
into all.tar and compress it, use:
tar -czvf all.tar.gz file1 file2 file3
To extract the original files from the compressed archive, use:
tar -xzvf all.tar.gz