Essential tools Flashcards

1
Q

Piping and redirection

A
|
>
>>
2>/dev/null
<
du -h / 2>/dev/null | sort -nr | head -n 5

./script.sh 2>errors.log 2>&1
all output and errors will be shown on a screen despite the first redirection of errors to errors.log file

file< commands > file2
ls nosuchfiles 2>/dev/null
all errors will be sent to nowhere

ls -l /etc | wc -show how many lines, words and characters are in the output of ls -l /etc commannd

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

Show environment vars

A

env

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

Stdin, stdout, stderr

A

stdin: 0
stdout: 1
stderr: 2

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

Show users logged in to the system

Show name of current user

A

who

whoami

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

grep

A

-R -recurcive
-l -show only file names
-w -match whole word
-A number -print number of lines after the match
-B number- print number of lines before the match
n- add line number

grep ‘^$’ -search for blank lines
Regexp should be surrounded by single quotes.

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

Man pages

A
  1. exec programs and shell commands
  2. system calls- function provided by kernel
  3. library calls
  4. special files typically found in /dev
  5. files formats and conventions
  6. games
  7. miscellaneous
  8. for sysadmins
  9. for non-standard kernel routines

man -k command= apropos command

mandb- this command is used to update man pages db

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

Vim

A
dd -delete line
yy -copy line
p -paste copied 
v- visual block
y -copy block which was visualized 
u -undo
crtl-r -redo
gg/+shift+g -go to the beginning  
G/shift+g - go to the end
cw- while in command mode immediately switches to insert mode removes current word and allows to change this to something else
cc-removes the line and put into insert mode
shift+r -replaces current chars with new ones while typing over

/text -forward search
?text- backwards search
n/?- moving forward/backward to the next occurrence of the search
^ -move the cursor to the beginning of the line
$- move the cursor to the end of the line
:%s/old/new/g - search and substitute from old value to new globally

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

Cockpit

A

http://localhost:9090

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

cat options

A
  • A -show non-printable symbols
  • b -number of lines
  • s suppress repeated empty lines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

cut
sort
tr

A
cut -f 1,2,3 -d : /etc/passwd | sort -n
-n- numerical sort
tr- translate
cut -f 1 -d : /etc/passwd | tr [a-z] [A-Z] - accounts will be shown in uppercase
the same: tr [:lower:] [:upper:]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

sed

A

sed -n 4p file -print fourth line of file
sed -i s/old/new file
-i - overwrite the file
sed -i -e ‘2d’ file1- delete second line of file1
-e -edit

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

Run a command being substituted, similar to sudo command

A

su -c “fdisk -l”

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

Redirect both errors and output to the file

A
vim myfile:
hdhjdjd
ls -la
\:wq
chmod u+x myfile
./myfile &amp;> alloutput
when running only ./myfile > alloutput without &amp;, an error message will be shown on display and output from ls -la will be added to alloutput file.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Redirect standard error to stdout

A

fdshfs 2>&1
benefit from this- using output from this command and redirecting it to somewhere else:
dshfs 2>&1 | grep -i ‘failed to search’
or
ls -la huj&raquo_space; myfile 2&>1
cat myfile => invalid option j…

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

Login as root into login shell

A

su -
su -l
su –login

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

Find files

A

find / -type f -size +100M
find / -exec grep -l user {} \; 2>/dev/null

find / -name "*.tar" -ctime 1
use weak quotes when using file globbing
\_\_\_\_\_
-name -name
-ctime n -last change time (in days)
-mtime n-modified within n days
-mtime +3 -modified more than 3 days ago
-atime -access time (in days)
-empty
-uid
-type f or -type -d
-user user_name- files belonging to specified user

find . -name myfile{1..100} -exec rm -rf {} \;

find /text -empty | xargs rm -f

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

Show differences between archive file and current files/dirs having the same name as contents of the archive

A

tar -dvf myarchive.tzr.gz

18
Q

Show information about the content of archive file

A

gzip file1 file2 file3

gzip -l file1.gz

19
Q

star

A
star -c -f=myarchive.tar dir1/ dir2/ file1 file2
-c-compress 
star -t -f=myarchive.tar
-t- list contents of archive 
then,
gzip myarchive.tar=> myarchive.tar.gz
gunzip myarchive.tar.gz

star -x -f=myarchive.tar=>
this will not override current existing files or dirs
______________
star -x -f=myarchive.tar file1

this will extract only file1 from myarchive.tar
___________
compress file with gzip using star
star -cz -f=myarchive2.tar.gz /dir1 file1

20
Q

Compress multiple individual files without deleting with the original files with bzip2

A

bzip2 -k MyFile1.txt MyFile2.txt MyFile3.txt

21
Q

Unzip archive with bzip2

A

bzip2 -d MyFile1.txt.bz2

bunzip MyFile1.txt.bz2

22
Q

Add executable permissions to dirs only.

So dedicated groups would be able to traverse through dirs, but not able to run scrips in those dirs

A

chmod ug-x -R dir1

chmod ug+X -R dir1

23
Q

Add/remove ugo privileges to a file or dir

A

chmod a+rx

chmod a-rwx

24
Q

Set suid to file

A

s is present in x position of owner of a file
=4
chmod u+s testfile
chmod 4740 testfile
setuid is used to execute files as if user was a owner
usr/sbin/passwd has sid

25
Set gid to dir
s is present in x position of group owner of file/dir =2 That means when files are created within that directory, those new files will inherit the group ownership of that parent directory. chmod g+s testfile chmod 2750 dir setgid is used to execute files as if user was a group owner
26
Set gid and sid simultaneously
chmod 6550 testfile
27
Preventing user from deleting file or dir with sticky bit
``` t is present in x position of others =1 chmod 1777 myfile chmod +t testfile tmp dir has sticky bit ```
28
Get user's group name | Get user's users name
id -gn | id -un
29
umask
``` /etc/bashrc -interactive shell /etc/profile -login shell The value which will be subtracted from default permissions: 777=default for dirs 666=default for files ___ umask u=rwx,g=,o= => umask value=0077 ``` In scripts: echo $(id -un) or echo "`id -un`"
30
info pages
info searches through /usr/share/info dir Used for GNU based systems use "n" keybutton to move to the next node use "p" key to move back use "u" to navigate to one level up use "H" to het help ``` info coreutils to look at exam for sections related to operations _____________ 1. info --apropos=tee=> coreutils 2. info coreutils tee ```
31
/usr/share/doc
programs might have info inside this dir | some of them might not have man pages, but have docs inside /usr/share/doc/
32
locate
locate passwd search in a system for files, docs, everything takes info from locate DB to do update DB run updatedb
33
whatis
whatis passwd | Look into manual pages
34
which
search for binaries located in PATH
35
Locate binaries, source and man pages
whereis | whereis passwd
36
Query for rpm docs
rpm -qd packagename
37
stat of the file, when it was created, modified etc
stat file1
38
tar
Add More Files To Tar File: tar -f archive.tar -r new/test2.txt Display Verbose Information: tar -cvf archive.tar Extract Tar File To Specific Directory: tar -xf archive.tar -C new/ Remove Files After Archiving: tar -cvf archive.tar test1.txt test2.txt --remove-files Extended Attribute Support, SELinux Support: tar -cf xattrs.tar test1.txt --xattrs --selinux
39
Gunzip into a different directory
gunzip -c file.gz > /THERE/file
40
Scp
scp myfile cloud_user@1.2.3.4:~/mydir/
41
Sftp
sftp cloud_user@1.2.3.4 sftp>? sftp>get myfile sftp>put file1