commands and switches Flashcards

1
Q

find [path] -name “[name]”

A

find files and subdirs

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

find [path] -type d -name “[dir]”

A

find subdirs

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

ldconfig –print-cache

A

Print the lists of directories and candidate libraries stored in the current cache. Pipe into grep to find if a particular library is installed and accessible.

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

type [cmd]

A

Find whether the given command is an alias, shell built-in, file, function, or keyword. Also displays path

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

type -t [cmd]

A

Show just type

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

type -p [cmd]

A

Show just path

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

type -a [cmd]

A

Show all info

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

du [paths]

A

Disk usage

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

du -h [path]

A

Disk usage in human readable form

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

strace -f [program]

A

Trace child processes

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

strace -o “filename”

A

Output to log

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

strace -p PID

A

Attach

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

strace trace=open

A

Show opened files

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

rename ‘s/[old regex]/[new regex]/’

A

Batch rename

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

rename ‘s/-//’ ./*

A

remove dashes in all names in current folder: (1st dash)

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

grep [path] -e [pattern]

A

Search for pattern in path

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

grep -r

A

recursive

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

grep -n

A

display line number

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

grep -w

A

search for whole word

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

grep -l

A

show just file names

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

[[ -a file ]]

A

Test if file/dir exists. Identical to -e

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

[[ -d file ]]

A

Test if directory exists

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

[[ -f file ]]

A

True if file exists and is a regular file.

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

[[ -e file ]]

A

Test if file/dir exists. Identical to -a

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

[[ -r file ]]

A

True if file exists and is readable

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

[[ -s file ]]

A

True if file exists and has a size greater than zero.

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

[[ -w file ]]

A

True if file exists and is writable

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

[[ -x file ]]

A

True if file exists and is executable

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

[[ file1 -nt file2

]]

A

True if file1 is newer than file 2

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

[[ file1 -ot file2 ]]

A

True if file1 is older than file2

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

[[ -v varname ]]

A

True if the shell variable varname is set (has been assigned a value).

32
Q

[[ -z string ]]

A

True if the length of string is zero

33
Q

[[ -n string ]]

A

True if the length of string is non-zero

34
Q

[[ arg1 -eq arg2 ]]

A

Arithmetic are equal

35
Q

[[ arg1 -ne arg2 ]]

A

Arithmetic not equal

36
Q

[[ arg1 -lt arg2 ]]

A

Arithmetic less than

37
Q

[[ arg1 -le arg2 ]]

A

Arithmetic less or equal

38
Q

[[ arg1 -gt arg2 ]]

A

Arithmetic greater than

39
Q

[[ arg1 -ge arg2 ]]

A

Arithmetic greater or equal

40
Q

[[ arg1 == arg2 ]]

A

String equality

41
Q

[[ arg1 != arg2 ]]

A

Strings different

42
Q

[[ arg1 < arg2 ]]

A

String 1 is lexicographically before string 2

43
Q

ls -l

A

long listing format

44
Q

ls -A

A

Almost all files: with hidden, no ./..

45
Q

ls -a

A

all files: hidden, ./..

46
Q

tail -F some.log

A

Track while adding

47
Q

rm -f

A

remove file force: no confirmation

48
Q

file [full path]

A

auto detect file type

49
Q

ldd [full path]

A

show static .so dependencies

50
Q

wc

A

word count

51
Q

wc -l

A

word count, just lines

52
Q

lsof

A

list open files

53
Q

lsof +D [path]

A

list open files within directory

54
Q

lsof +r 5

A

list open files, refresh every 5 sec

55
Q

ps

A

active processes by my user

56
Q

ps -u guga

A

all active processes by user guga

57
Q

uniq -c

A

Show count of unique entries in sorted input

58
Q

sort [file]

A

sort lines

59
Q

tcpdump -qns 0 -r [file]

A

dump pcap contents

  • q: quiet, less protocol info
  • n: don’t convert ip to names
  • s [X]: snap X bytes of data from the packet. -s 0: don’t display the packet
  • r: read [file]
60
Q

grep -o

A

Print only matching parts of a matching line

61
Q

grep -P

A

Pattern is a perl-compatible regex

62
Q

xargs -n 1

A

–max-lines=1 : use at most 1 argument per command line

63
Q

xargs -t

A

synonym to –verbose, show all commands

64
Q

xargs -I % (capital i)

A

replace % with the input. Doesn’t have to use % as the replace-str

65
Q

xargs -P 7

A

run at most 7 processes

66
Q

find /tmp -name core -type f -print0 | xargs -0 /bin/rm -f

A

Find files named core in or below the directory /tmp and delete them, processing filenames in such a way that file or directory names containing spaces or newlines are correctly handled.

67
Q

remote copy (directory)

A

scp -r username@from_host:/remote/directory/ /local/directory/

68
Q

ls only folders

A

ls -d */

huh?

69
Q

in htop, show open files

A

l

70
Q

in htop, strace

A

s

71
Q

processor bar colors in htop

A

Blue/green/red: low-pri/normal/kernel threads

72
Q

Memory bar colors in htop

A

Green/blue/yellow: used/buffer/cache

73
Q

in htop, show env

A

e

74
Q

xargs show commands

A

–verbose, -t

75
Q

xargs confirm each command separately

A

–interactive