Linux Commands Flashcards

Practice Linux Terminal Commands

1
Q

How to see all running processes in Linux System ?

A

htop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to create alias ?

A

alias list=’ls’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to list all aliases?

A

alias

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to search in Linux ?

A

locate filename
find / -name sample.txt # search for txt extension in given space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to get hardware info ?

A

lscpulsmemlshw

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to read & execute file contents?

A

source filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is TCL interpretor ?

A

“Tool Command Language” (it is pronounced “tickle”)Its an command line interpreator .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to get Welcome String after launching Linux Terminal ?

A

in .bashrc write your welcome string ,echo ‘Welcome Message’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the structure of Linux command ?

A

cmd -optons target
ls -lrt /tmp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to get the calendar in terminal ?

A

cal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to get the date ?

A

date

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to get the Disk Usage ?

A

df -h

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to get the file & directory size ?

A

du -sh /rooot/*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to see processes that consume the most system resources?

A

top

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to get the short description of commands ?

A

whatis ls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to get the location of commands & its manual

A

wehereis ls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to get the full path of command ?

A

which pwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to list the directory contents in full detail in kb mb gb ?

A

ls -lah

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to go to the home directory ?

A

cdcd ~

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How to Stop Particular Command in Terminal

A

ctrl + c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How to List Directory contents ?

A

ls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How to view file contents ?

A

cat filename
less filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How to redirect ouptut ?

A

By using redirectional operator : cat /dev/random > /tmp/tempfile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to clear terminal screen in linux ?

A

clear or ctrl + l

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How to get processor details ?
# show detail of each socket cat /proc/cpuinfo lscpu
26
How to get ram details in Linux ?
cat /proc/meminfo lsmem
27
How to view links of files ?
ls -l
28
How to test a command from inside a manpage ?
type command followed by exclamation mark. !ls /proc/
29
Search for string inside a man page ?
search string followed by forward slash : /-l
30
How many sections are in man page ?
Total 8 Sections.
31
How to get Help for special Files using man ?
Specials Files And Devices are described under section 4 of man pages man 4 filename man 4 urandom`
32
What is long command for ls ?
ls -l
33
How to go to one level up to get relative path ?
#/home/dir1/dir2#/home/dir1/dir3pwd/dir1/dir2/../dir3/
34
What means pwd ?
print working directory
35
How to find name server of Domain usinglinux terminal ?
host is a simple utility for performing DNS lookups. It is normally used to convert names to IP addresses and vice versa. When no arguments or options are given, host prints a short summary of its command line arguments and options. host -vt ns ares.res.in host -vt ns 14.139.225.232
36
How to get pid of running application ?
pid of firefox
37
How to list all PIDs ?
#pidstat
38
How to list all open files in the whole system ?
lsof
39
How to list all files used by an user process ?
lsof -u username
40
Which Linux Command can we use to know, what files are opened by user ?
lsof -u username
41
What is the Default shell MAC OS ?
ZSH
42
Where to get random values in linux ?
/dev/random /dev/urandom
43
Where to write data so that it can discarded ?
redirect the output to /dev/null
44
Which Directory represents process ?
/proc
45
Which Directory represents devices ?
/dev
46
What is a command to read file contents line by line in paced navigation ?
more filename
47
How to exit from more commnand ?
q , ctrl+c , ctrl +z
48
What is a command to display all block devices in a system ?
lsblk
49
What is the command to display detail information of mount points ?
mount
50
How to list the permission of parent directory
ls -ld /mnt
51
What is command to display process running in background ?
ps -elf
52
Which editor comes by default with every Linux distribution ?
vi editor
53
What is the full form of vi ?
visual editor
54
Which Editor supports spell checking ?
Nano editor
55
How to long list files ?
ls -l
56
How to list hidden files ?
ls -a
57
Which command read from file and display it on standard output ?
cat command
58
What is the full form of cat ?
Concatenate
59
How to see help of command ?
man, info, help
60
Which command is used for copy ?
cp
61
Which command is used to show current directory ?
pwd
62
What is the full form of PWD
Print working directory
63
How to create directory or folder ?
mkdir
64
How to list running processes in Linux ?
ps -elf command
65
How to display process tree of running processes ?
ps -ejH
66
How to display all processes & threads in system ?
ps -elf
67
How to create a file ?
touch file name
68
How to Telnet on port 80 ?
telnet ip port
69
How to display TCP,UDP network connections and elaborate options?
netstat -tunap -t tcp -u udp -n ip & ports-all listening & non listening ports -p program id
70
How to search man for commands ?
man -k command
71
How to ping for 4 times ?
ping -c 8.8.8.8
72
How to sync system date with network time servers ?
ntpd -qg
73
What is the portal for online traceroute and other network tools?
gsuitetools
74
How to monitor continuous log of service only ?
journalctl -f -u sshd.service
75
How to see log of a service of last one hour ?
journalctl -u sshd.servce - -since "1 hour ago"
76
How to see event log of last 1 hour
journalctl --since "1 hour ago"
77
How to set journalctl not to display hint ?
journalctl -q
78
How to show last boot log ?
jounalctl -b -1
79
How to monitor a log file in real time ?
tail -f
80
How to display last 10 lines of log
tail -n 10
81
How to show log of last booting process ?
journalctl --list-boots
82
Real time log monitoring commands ?
journalctl -f tail -f
83
How to read contents of a file one page at a time in continuous mode ?
less filename
84
What is the command to manage system services ?
setup
85
What is the command to show network interfaces ?
ip link
86
What is the command to show routes ?
netstat -r
87
How to show the current all running processes of users
ps -aux | sort
88
How to know which user are you logged in
whoami
89
How to know the groups user belong to ?
groups
90
What is the command to show IO blocks of file and directory ?
stat file/directory
91
What is the command to show IP & of MAC Address of network interface ?
ip address x x 0
92
How to clear ARP cache ?
arp -n
93
How to clear ARP cache of an IP Address ?
arp -d 10.0.0.1
94
What is the switch user command ?
su
95
How to get help of nmap ?
nmap --helpinfo nmapman nmap
96
How to search a string under man pages ?
To search for a specific term, use forward slash (/) or question mark (?) followed by the term or phrase. The forward slash searches forward through the document, and the question mark searches backward through the document. The key n moves to the next match, p moves back
97
How to do Basic OS detect scan & version detection in nmap ?
nmap -A
98
How to use Time template in nmap
nmap - T4 ip address-T values are 1 to 5
99
Which website is legal to test and learn nmap commands ?
scanme.nmap.org
100
What does the switch -A do in nmap ?
service version scan nmap -A -T4 ip
101
What does the switch -T4 do
Timing Template
102
How to perform Stealth Scan ?
nmap -sS ip
103
How to know filter ports on host ?
By using stealth scan ,nmap -sS ip
104
How to perform service version scan with traceroute ?
nmap -A -T4 14.139.225.228
105
How to captutre 50 packets of network card from terminal & save it in pcap file ?
tcpdump -i eth0 -v -c 50 -w /home/analyst/capture.pcap
106
How to know the exact date of last system reboot ?
journalctl --list-boots
107
What command is for detail version scan
nmap -v -sV --version-all -p- 172.18.1.5
108
How to check how many users are remotely connected to a Linux Server
finger & pinky command
109
How to remove package in centos 7 by usng yum
yum erase iscsi-initiator-utils*
110
How to , nmap command which show open ports only , scan for os detect., save to file
nmap -O -T4 -p80,443 172.21.0.0/22 --open -oG fileName.txt
111
How to kill all processes of particular program at once ?
killall python3killall firefox
112
How to know , what command is doing ?
We have to use strace command .strace pinky 2>&1 | more
113
Display file contents line by line
less
114
How to get total no. of lines in a file ?
wc -l /etc/passwd man ls | wc -l
115
How to create a sub directory with auto create parent directory ?
mkdir -p /dir1/dir2
116
Write a bash code to display Hangout... infinetly for 2 seconds interval, now stop this code after running , now display what is running in background , it may be the code
``` #!/bin/bash while [ true ]; do sleep 2 ; echo "Hanging Out...." done ```
117
How to run a command & send it to background ?
Use ampersand after command sleep.sh &
118
How to stop an running command ?
ctrl + c it sends the command to background
119
How to display the status of tasks in current session ?
jobs
120
How to delete a File ?
rm filename
121
How to delete a directory ?
rm -rf
122
Long list the contents of /usr/bin/ , count the output lines , save to file ?
ls -l /usr/bin/ | wc -l > bin.txt
123
How to use an conditional Operator on command line , ls a file , if succesful create a new file ?
ls -l .bashrc && touch newfile.txt
124
How to create an string variable in command line ?
STR=$'This is Some Text Example'
125
Create a string variable , when we echo the variable then output shoulb be exactly like this . 1.This is a Line 2.This is a Line 3.This is a Line
STR=$'1.This is a Line\n2.This is a Line\n3.This is a Line . ' echo $STR
126
How to print value of variable on terminal ?
echo "$STR"
127
Create a string variable ,output should be exactly like this . 1.This is a Line 2.This is a Line 3.This is a Line Save this output to file , Read the file , pipe the output & sort the ouptput in reverse order
``` STR=$'1.This is a Line\n2.This is a Line\n3.This is a Line' echo "$STR" echo "$STR" > lines.txt cat lines.txt | sort -r ```
128
How to get details of parent directory
ls -ld
129
1.This is a Line 2.This is a Line 3.This is a Line Create the file with above contents , now print the file on standard output , pipe it to grep , search for 3 save the match string to file
STR=$'1. This is a Line\n2. This is a Line\n3. This is a Line' echo "$STR" > lines.txt cat lines.txt | grep 3 >match.txt
130
What is the right way to store in variable ?
Use single qoutes STR=$'1. This is a Line\n2. This is a Line\n3. This is a Line'
131
How to sort contents of Files in reverse order ?
caty lines.txt | sort -r
132
How to append to a file ?
We have to use redirectional operator ``` echo "Something" > append.txt echo "Another Thing" >> append.txt ```
133
How to send command error message to null ?
ls -l /wrong/Path > /dev/null
134
How to print last 10 lines of text file
tail -n 10 /var/log
135
How to keep file open & display the changes continously ?
tail -f /var/log
136
Not Display the first 10 lines of a file
head -n 10 /var/log
137
How to go to the start - End of a long command typed on terminal ?
ctrl +a & ctrl +e
138
How to watch history of commands line by line ?
history | less
139
How to search in history for specific command ?
history | grep iscsi
140
How to Repeat last command in terminal ?
use Double exlamation symbols to execute last commands # !!
141
How to execute a particular line of history command ?
use excalamation symbol followed by line number , # !56
142
How to count a word in a file ?
cat abc.txt | wc -w
143
How to crteate an ssh keys ?
ssh-keygen -t rsa
144
How to know all open instances of Directory ?
lsof +D /root
145
How to query a NFS mount ?
``` showmount -e nfsServerIP ```
146
Create an alias show for this command , echo 'Hello All'
alias show="echo 'Hello'"
147
What is systemd journal ?
systemd-journal is a system service that collects and stores logging data
148
How to query systemd journal ?
journalctl
149
In Linux Centos 7 , how log is saved & stored ?
Log is stored by systemd journals
150
How to search & Cat multiple files
cat /etc/*rel* This command search release file & display contents
151
How to remove multiple packes by multiple lines
``` yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine ```
152
How to dry run an shell script ?
We have to use an option --dry-run bash myscript.sh --dry-run
153
How to sync system date from internet in linux
ntpd -qg