linux commands Flashcards
(27 cards)
Which command shows the size of files and folders in the current directory?
du -h
How to display the contents of a file line by line with line numbers?
nl filename
How to execute a file if it is executable? Provide an example
./script.sh
How to set permissions for groups and users using the chmod command?
chmod u+x file:
chmod g+w file:
Which command shows the available free space on the disk?
df -h
How to check the last modification date and time of a file?
stat filename
What is the difference between the commands ls -l and ls -a?
is the difference between the commands ls -l and ls -a?
o ls -l: Lists files in long format, showing permissions, owners, size, and
modification date.
o ls -a: Lists all files, including hidden files (those starting with a dot)
How to display the structure of a directory as a tree? Specify the command.
tree
How to run an application or command in the background?
./myprogram &
Write a command to display the last 20 commands executed in the terminal.
history | tail -20
How to clear the terminal screen?
clear
How to redirect the output of a command to a file?
command > filename
Write an example of creating a symbolic link to a file.
ln -s /path/to/file /path/to/symlink
How to find all files of a specific size in a directory?
find . -size +100M
How to delete all files with the .log extension in the current directory?
rm *.log
how to create a bash script and make it executable?
nano script.sh.
chmod +x script.sh.
How to automate script execution during system startup?
/etc/rc.local
How to check which packages are installed on the system using apt?
pt list –installed
What is the .bashrc file, and what is it used for?
What is the .bashrc file, and what is it used for?
How to enable error output in a bash script?
Add set -e at the beginning of the script to stop the execution on errors or set -
x to print each command before executing it
How to find the current user in Linux? Specify the command.
whoami
How to terminate a process using the kill command?
kill PID (replace PID with the process ID, which you can find using ps or top)
Which command is used to change the user password in Linux?
passwd
- How to display the contents of a file with line numbers, starting from a specific line?
sed -n ‘5,$=’ filename