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
Q

How to get processor details ?

A

show detail of each socket

cat /proc/cpuinfo

lscpu

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

How to get ram details in Linux ?

A

cat /proc/meminfo

lsmem

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

How to view links of files ?

A

ls -l

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

How to test a command from inside a manpage ?

A

type command followed by exclamation mark. !ls /proc/

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

Search for string inside a man page ?

A

search string followed by forward slash : /-l

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

How many sections are in man page ?

A

Total 8 Sections.

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

How to get Help for special Files using man ?

A

Specials Files And Devices are described under section 4 of man pages
man 4 filename
man 4 urandom`

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

What is long command for ls ?

A

ls -l

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

How to go to one level up to get relative path ?

A

/home/dir1/dir2#/home/dir1/dir3pwd/dir1/dir2/../dir3/

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

What means pwd ?

A

print working directory

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

How to find name server of Domain usinglinux terminal ?

A

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

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

How to get pid of running application ?

A

pid of firefox

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

How to list all PIDs ?

A

pidstat

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

How to list all open files in the whole system ?

A

lsof

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

How to list all files used by an user process ?

A

lsof -u username

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

Which Linux Command can we use to know, what files are opened by user ?

A

lsof -u username

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

What is the Default shell MAC OS ?

A

ZSH

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

Where to get random values in linux ?

A

/dev/random
/dev/urandom

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

Where to write data so that it can discarded ?

A

redirect the output to /dev/null

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

Which Directory represents process ?

A

/proc

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

Which Directory represents devices ?

A

/dev

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

What is a command to read file contents line by line in paced navigation ?

A

more filename

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

How to exit from more commnand ?

A

q , ctrl+c , ctrl +z

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

What is a command to display all block devices in a system ?

A

lsblk

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

What is the command to display detail information of mount points ?

A

mount

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

How to list the permission of parent directory

A

ls -ld /mnt

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

What is command to display process running in background ?

A

ps -elf

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

Which editor comes by default with every Linux distribution ?

A

vi editor

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

What is the full form of vi ?

A

visual editor

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

Which Editor supports spell checking ?

A

Nano editor

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

How to long list files ?

A

ls -l

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

How to list hidden files ?

A

ls -a

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

Which command read from file and display it on standard output ?

A

cat command

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

What is the full form of cat ?

A

Concatenate

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

How to see help of command ?

A

man,
info,
help

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

Which command is used for copy ?

A

cp

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

Which command is used to show current directory ?

A

pwd

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

What is the full form of PWD

A

Print working directory

63
Q

How to create directory or folder ?

A

mkdir

64
Q

How to list running processes in Linux ?

A

ps -elf command

65
Q

How to display process tree of running processes ?

A

ps -ejH

66
Q

How to display all processes & threads in system ?

A

ps -elf

67
Q

How to create a file ?

A

touch file name

68
Q

How to Telnet on port 80 ?

A

telnet ip port

69
Q

How to display TCP,UDP network connections and elaborate options?

A

netstat -tunap
-t tcp
-u udp
-n ip & ports-all listening & non listening ports
-p program id

70
Q

How to search man for commands ?

A

man -k command

71
Q

How to ping for 4 times ?

A

ping -c 8.8.8.8

72
Q

How to sync system date with network time servers ?

A

ntpd -qg

73
Q

What is the portal for online traceroute and other network tools?

A

gsuitetools

74
Q

How to monitor continuous log of service only ?

A

journalctl -f -u sshd.service

75
Q

How to see log of a service of last one hour ?

A

journalctl -u sshd.servce - -since “1 hour ago”

76
Q

How to see event log of last 1 hour

A

journalctl –since “1 hour ago”

77
Q

How to set journalctl not to display hint ?

A

journalctl -q

78
Q

How to show last boot log ?

A

jounalctl -b -1

79
Q

How to monitor a log file in real time ?

A

tail -f

80
Q

How to display last 10 lines of log

A

tail -n 10

81
Q

How to show log of last booting process ?

A

journalctl –list-boots

82
Q

Real time log monitoring commands ?

A

journalctl -f
tail -f

83
Q

How to read contents of a file one page at a time in continuous mode ?

A

less filename

84
Q

What is the command to manage system services ?

A

setup

85
Q

What is the command to show network interfaces ?

A

ip link

86
Q

What is the command to show routes ?

A

netstat -r

87
Q

How to show the current all running processes of users

A

ps -aux | sort

88
Q

How to know which user are you logged in

A

whoami

89
Q

How to know the groups user belong to ?

A

groups

90
Q

What is the command to show IO blocks of file and directory ?

A

stat file/directory

91
Q

What is the command to show IP & of MAC Address of network interface ?

A

ip address x x 0

92
Q

How to clear ARP cache ?

A

arp -n

93
Q

How to clear ARP cache of an IP Address ?

A

arp -d 10.0.0.1

94
Q

What is the switch user command ?

A

su

95
Q

How to get help of nmap ?

A

nmap –helpinfo nmapman nmap

96
Q

How to search a string under man pages ?

A

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
Q

How to do Basic OS detect scan & version detection in nmap ?

A

nmap -A

98
Q

How to use Time template in nmap

A

nmap - T4 ip address-T values are 1 to 5

99
Q

Which website is legal to test and learn nmap commands ?

A

scanme.nmap.org

100
Q

What does the switch -A do in nmap ?

A

service version scan nmap -A -T4 ip

101
Q

What does the switch -T4 do

A

Timing Template

102
Q

How to perform Stealth Scan ?

A

nmap -sS ip

103
Q

How to know filter ports on host ?

A

By using stealth scan ,nmap -sS ip

104
Q

How to perform service version scan with traceroute ?

A

nmap -A -T4 14.139.225.228

105
Q

How to captutre 50 packets of network card from terminal & save it in pcap file ?

A

tcpdump -i eth0 -v -c 50 -w /home/analyst/capture.pcap

106
Q

How to know the exact date of last system reboot ?

A

journalctl –list-boots

107
Q

What command is for detail version scan

A

nmap -v -sV –version-all -p- 172.18.1.5

108
Q

How to check how many users are remotely connected to a Linux Server

A

finger & pinky command

109
Q

How to remove package in centos 7 by usng yum

A

yum erase iscsi-initiator-utils*

110
Q

How to , nmap command which show open ports only , scan for os detect., save to file

A

nmap -O -T4 -p80,443 172.21.0.0/22 –open -oG fileName.txt

111
Q

How to kill all processes of particular program at once ?

A

killall python3killall firefox

112
Q

How to know , what command is doing ?

A

We have to use strace command .strace pinky 2>&1 | more

113
Q

Display file contents line by line

A

less

114
Q

How to get total no. of lines in a file ?

A

wc -l /etc/passwd
man ls | wc -l

115
Q

How to create a sub directory with auto create parent directory ?

A

mkdir -p /dir1/dir2

116
Q

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

A
#!/bin/bash

while [ true ];
do
    sleep 2 ;
    echo "Hanging Out...."
    
done  
117
Q

How to run a command & send it to background ?

A

Use ampersand after command
sleep.sh &

118
Q

How to stop an running command ?

A

ctrl + c
it sends the command to background

119
Q

How to display the status of tasks in current session ?

A

jobs

120
Q

How to delete a File ?

A

rm filename

121
Q

How to delete a directory ?

A

rm -rf

122
Q

Long list the contents of /usr/bin/ ,
count the output lines ,
save to file ?

A

ls -l /usr/bin/ | wc -l > bin.txt

123
Q

How to use an conditional Operator on command line ,
ls a file , if succesful create a new file ?

A

ls -l .bashrc && touch newfile.txt

124
Q

How to create an string variable in command line ?

A

STR=$’This is Some Text Example’

125
Q

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

A

STR=$’1.This is a Line\n2.This is a Line\n3.This is a Line . ‘
echo $STR

126
Q

How to print value of variable on terminal ?

A

echo “$STR”

127
Q

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

A
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
Q

How to get details of parent directory

A

ls -ld

129
Q

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

A

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
Q

What is the right way to store in variable ?

A

Use single qoutes
STR=$’1. This is a Line\n2. This is a Line\n3. This is a Line’

131
Q

How to sort contents of Files in reverse order ?

A

caty lines.txt | sort -r

132
Q

How to append to a file ?

A

We have to use redirectional operator
~~~
echo “Something” > append.txt
echo “Another Thing”&raquo_space; append.txt
~~~

133
Q

How to send command error message to null ?

A

ls -l /wrong/Path > /dev/null

134
Q

How to print last 10 lines of text file

A

tail -n 10 /var/log

135
Q

How to keep file open & display the changes continously ?

A

tail -f /var/log

136
Q

Not Display the first 10 lines of a file

A

head -n 10 /var/log

137
Q

How to go to the start - End of a long command typed on terminal ?

A

ctrl +a & ctrl +e

138
Q

How to watch history of commands line by line ?

A

history | less

139
Q

How to search in history for specific command ?

A

history | grep iscsi

140
Q

How to Repeat last command in terminal ?

A

use Double exlamation symbols to execute last commands
# !!

141
Q

How to execute a particular line of history command ?

A

use excalamation symbol followed by line number ,
# !56

142
Q

How to count a word in a file ?

A

cat abc.txt | wc -w

143
Q

How to crteate an ssh keys ?

A

ssh-keygen -t rsa

144
Q

How to know all open instances of Directory ?

A

lsof +D /root

145
Q

How to query a NFS mount ?

A
showmount -e nfsServerIP 
146
Q

Create an alias show for this command ,

echo ‘Hello All’

A

alias show=”echo ‘Hello’”

147
Q

What is systemd journal ?

A

systemd-journal is a system service that collects and stores logging data

148
Q

How to query systemd journal ?

A

journalctl

149
Q

In Linux Centos 7 , how log is saved & stored ?

A

Log is stored by systemd journals

150
Q

How to search & Cat multiple files

A

cat /etc/rel
This command search release file & display contents

151
Q

How to remove multiple packes by multiple lines

A
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
152
Q

How to dry run an shell script ?

A

We have to use an option –dry-run
bash myscript.sh –dry-run

153
Q

How to sync system date from internet in linux

A

ntpd -qg