Linux Commands Flashcards

1
Q

Is Linux same as UNIX?

A

No, they are not the same.
They are different OS and UNIX was created long before Linux, which is said to be UNIX-like OS.
Linux is used pretty much everywhere, PCs, servers, game dev, mobiles etc while unix is mostly used in servers, workstations

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

What is:
cd ~

A

Go to home dir of current user

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

Absolute path vs relative path?

A

Absolute always starts from root /root/home/kmylonas/Document
If a path starts with / then its an absolute path.
Relative is from where you are now for example if you’re kmylonas:
cd Documets or cd ./Documentrs

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

rmdir can only remove empty directories?

A

Yes

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

How to remove non empty dir?

A

rm -r

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

Whats the difference between && and ; ??

A

&& executes sequence of commands only if all of them succeed
; executes sequence of commands independently, some may fail

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

What does:
chmod 753 file.txt

A

file.txt permissions:
user: rwx
group: rx
others: wx

It is equivalent to:
chmod u=rwx,g=rx,o=wx file.xt

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

Use case of chmod -R ?

A

-R is used to change permission to directory and its contents

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

What is a softlink and how to create it?

A

A softlink is like a shortcut in windows.
Create it with ln -s original_file shortcut_file

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

Changes to softlinks apply to original file?

A

Yes

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

What happens to soft links when you delete their original file?

A

They have no use..

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

Can you have a softlink for directories?

A

Yes

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

How to create hardlinks?

A

ln sourcefile hardlinkname

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

ls -l shows the number of softlinks or hardlinks?

A

Number of hardlinks

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

Can you create hardlink for directories?

A

No.

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

Should you use absolute path or relative when creating links?

A

According to giatrakos, absolute path

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

If you have an original file and a hardlink, what happens when you delete the original file?

A

You can still access the original data through the hardlink.

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

What fits to the ?
find -type ? -name “file*”

A

? can be f if you want files whose name start with “file”
? can be d if you want directories …
if no type set then find command returns everything

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

find -type f -perm 701 -name “file*”

A

find files with perm rwx—–x and name prefix file

20
Q

Whats the use of []?

A

Regex like [a-Z] or [abcd] etc

21
Q

Whats the use of {}?

A

echo file{1..10..2} will create file1 file3 file5 … file10

22
Q

Whats the usage of tee command?

A

tee file1 file2…
Takes input from stdin and outputs to each file (file1, file2..) and to the stdout
For example if you want to echo a message and log it to a logfile tee would be a way to go

23
Q

How to use “more”

A

spacebar -> next page
b -> previous page
enter -> next line
q -> exit

24
Q

Whats the main advantage of less against more?

A

Less doesn’t have to load the whole input file at once so it’s the way to go for big files.

25
Q

grep -n “Stat” sample_data/

A

Search whole directory for line matches containing Stat
-n will return the line number of each match

26
Q

!grep -r “Stat” sample_data/

A

Search subdirectories recursively

27
Q

!grep -l “Stat” sample_data/

A

Instead of returning line numbers return the filenames that you found the match

28
Q

!grep -w “Census” sample_data/README.md

A

search for a specific word
-cw would return the number lines that match
-cvw return the number of lines that didnt match

29
Q

Defaults about sort command?

A

delimiter is considered whitespace
sorts alphabetically, not numerically

30
Q

What’s the use of cp -R (equivalent to cp -r)

A

Use -R to copy entire directory with its contents

31
Q

mv -i
cp -i

What’s the use of -I flag?

A

With -I those commands will prompt you before proceeding, so you make sure that you don’t override any preexisting files

32
Q

chmod a=rw file.txt

A

all: owner, group,others = rw permissions

33
Q

usermod -a -G my_group newperson

A

Add new user to the new group

34
Q

usermod -g my_group newperson

A

change the primeary group of the user

35
Q

mkdir testchown
touch ./testchown/file.txt
chown -R newperson testchown

A

newsperson is the user of the testchown directory and its contents like file.txt

36
Q

!find . -type f -perm 701 -print -exec chmod 644 {} \;

A

In current directory find all files with permissions 701 and change their permissions to 644. Its common to use exec for this use case

37
Q

!find . -user root -iname “*.JSON”

A

in current directory find files where user owner is root and name ends in .json case insensitive

38
Q

!find -L /content -samefile testchmod/myfile.fd

A

find softlinks and hardilnks of my file.fd under testchmod

39
Q

!grep -w “Census” sample_data/README.md

A

Search for a distinct word Census.

40
Q

wc -c

A

write total number of bytes

41
Q

wc -m

A

write the total number of characters

42
Q

sort -r +2 file.txt

A

sort in reversed alphabetical order and the key is the third column

43
Q

!sort -t” “ -k 3.3,3.5 sortmylines.txt

A

delimiter = “ “
Start sorting from 3d char of 3d field till 5th char of 3d field

44
Q

!sort -c sortmylines.txt

A

check if a file is already sorted

45
Q

cut -f2-3 -d” “ sortmylines.txt

A

show from 2 until 3d column
if it was -f2-5 would show column2,3,4,5

equivalent would be -f2,3