Learning the Shell Flashcards

1
Q

date

A

Outputs date and time per host settings

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

cal

A

Outputs calendar for the current month per host settings

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

df

A

Outputs the ‘disk free’ / the current amount of free space on your disk drives

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

ln

[ … how to create a hard link ]
[ … how to create a symbolic link ]

A

Creates hard and symbolic links

ln FILE LINK => creates a hard link

ln -s ITEM LINK => creates a symbolic link where ITEM is either a file or a directory

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

rm

A

Removes files and directories.

Note: use of the ‘-r’ may be required to remove directories on select Linux based OS’s.

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

mkdir

A

Creates directories

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

mv

A

Moves / Renames flies and directories

mv dir1/fun dir2 => moves the ‘fun’ file from directory 1 (‘dir1) to directory 2 (‘dir2’)

mv fun funner => changes the file / directory named ‘fun’ to ‘funner’

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

cp

A

Copies directories or files

cp dir1/fun dir2 => copies the ‘fun’ file in directory 1 (‘dir1’) to directory 2 (‘dir2’)

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

less

[ … navigation commands ]

A

View file contents within the command line interface.

Navigation commands:

b / PAGE UP : Scroll back one page

spacebar / PAGE DOWN : Scroll forward one page

up arrow : Scroll up one line

down arrow : Scroll down one line

G : Move to the end of the text file

1G or g : Move to the beginning of the text file

/characters : Search forward to the next occurrence of characters

n : Search for the next occurrence of the previous search

h : Display help screen

q : Quit less

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

file

A

Outputs the file type

file FILE

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

ls

A

Outputs a list of directory contents

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

pwd

A

Print Working Directory : outputs / prints the name of the current working directory

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

cd

A

Change Directory : Changes to the specified directory

On the desktop there is a folder named ‘dir1’

From Desktop : cd dir1 => moves the operator to the working directory to ‘dir1’

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

exit

bye

A

Exit or Bye can be used to end the terminal session

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

free

A

Outputs amount of free memory on the host

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

type

A

Outputs how a command name is interpreted

type ls => ‘ls is /bin/ls’
[ ^ from MacOS ]

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

which

A

Outputs which executable program will be executed

which ls => /bin/ls
[ ^ from MacOS ]

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

man

A

Outputs a command’s manual page – i.e. the detailed documentation of the command and its options

man COMMAND

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

apropos

A

Outputs a list of appropriate commands like a search function

apropos COMMAND

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

info

A

Outputs a command’s info entry

info COMMAND

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

whatis

A

Outputs a brief description of a command

whatis COMMAND

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

alias

A

Creates an alias for a command durable for the terminal session.

if ‘cd /user; ls; cd -‘ is a common line, then

alias foo=’cd /user; ls; cd -‘, then typing

‘foo’ will execute ‘cd /user; ls; cd-‘ for the remainder of the terminal session.

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

cat

A

Concatenates files

you have movie.mpeg.001 … movie.mpeg.099 =>

cat movie.mpeg.0* > movie.mpeg

^ concatenates the files into a single file

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

sort

A

Sort lines of text

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

uniq

A

Reports on or omits repeated lines

26
Q

wc

A

Print newline, word, and byte counts for each file

27
Q

grep

A

Outputs lines matching a pattern

grep STRING, for example ‘ls /bin | grep zip’ will return all items listed in ‘/bin’ that contain ‘zip’

28
Q

head

A

Outputs the first part of a file

29
Q

tail

A

Outputs the last part of a file

30
Q

tee

A

Read from standard input and write to standard output and files

31
Q

echo

A

Outputs a line of text

echo ‘Hello World!’ => ‘Hello World!’

32
Q

clear

A

Clears the screen

33
Q

history

A

Outputs the contents of the history list

34
Q

ps

A

Outputs a snapshot of current processes

35
Q

top

A

Outputs tasks

36
Q

jobs

A

Outputs a list of active jobs

37
Q

Long listing fields

-rw-r–r– 1 root root 32059 2012-04-03 11:05 oo-cd-cover.odf

A
  • rw-r-r– : Access rights to the file.
  • : The first character indicates the type of file. Among the different types, a leading dash (‘-‘) means a regular file, while a ‘d’ indicates a directory.

‘rw-‘ : The next three characters are the access rights for the file’s owner.
‘r–’ : The next three are for members of the file group.

‘r–’ : The final three are for everyone else.

1 : File’s number of hard links.

root : The user name of the file’s owner.

root : The name of the group that owns the file.

32059 : Size of the file in bytes.

2012-04-03 11:05 : Date and time when the file was last modified.

oo-cd-cover.odf : Name of the file.

38
Q

Redirecting standard output

A

There are two options:

1: ‘>’ overwrites
e.g. ls -l /usr/bin > ls-output.txt => creates .txt
ls -l /usr/bin > ls-output.txt => overwrites the above

2: ‘»’ appends
e.g. ls -l /usr/bin&raquo_space; ls-output.txt => creates .txt
ls -l /usr/bin&raquo_space; ls-output.txt => appends a second output of /usr/bin to the .txt created, above

Note:
0 = standard input
1 = standard output
2 = standard error

39
Q

Redirecting standard error

A

‘2>’

ls -l /usr/bin 2> ls-error.txt => ‘2>’ redirects standard errors to ‘ls-error.txt’

Note:
0 = standard input
1 = standard output
2 = standard error

40
Q

Redirecting standard output and standard error

A

There are two options:

  1. Original version:
    ls -l /usr/bin > ls-output.txt 2>&1^ redirects standard output, then makes standard error ‘2’ and input to standard output ‘>&1’
  2. New jack version:
    ls -l /usr/bin &> ls-output.txt^ redirects standard input and error ‘&>’ to ‘ls-output.txt
41
Q

Pipelines

A

COMMAND1 | COMMAND2

COMMAND1 becomes input for COMMAND2

Pipelines are used to ‘filter’ as in:
ls /bin /usr/bin | sort | less

^ list contents of ‘/bin’ and ‘/usr/bin’, then input to ‘sort’ to order the list, the ‘less’ to output to terminal

  • or -

ls /bin /usr/bin | sort | uniq | less

^ as previous, but, sort, then deduplicate (‘uniq’), then ‘less’ to output to terminal

42
Q

Expansion

1) pathname expansion
2) tilde expansion
3) arithmetic expansion
4) brace expansion
5) parameter expansion

A

Expansion is the process by which elements of command are expanded by the interpreter.

1) pathname expansion: expansion of the wildcard (‘ * ‘)
e. g. echo D* => all items starting with ‘D’

2) tilde expansion: expansion of the ‘ ~ ‘
e. g. echo ~ => /home/me (the current user)

3) ' $((2+2))' => 4
      ' + ' addition
      ' - ' subtraction
      ' * ' multiplication
      ' ** ' exponentiation
      ' / ' division (no remainder)
      ' % ' modulo / reminder (only the remainder)

4) brace expansion: use of ‘ { } ‘ to create multiple text strings from a pattern contained within the braces.
e. g. ‘ file-0{1..5} ‘ => creates five directories named file-01, file-02, file-03, file-04, and file-05

5) parameter expansion : taps the system’s ability to store small chunks of data and to give each chuck a name.
e. g. echo $USER => me (the current user)

43
Q

id

A

Display the user identity.

44
Q

chmod

A

Change a file’s mode.

45
Q

umask

A

Set the default file permissions.

46
Q

su

A

Run a shell as another user.

generic form: su [-[l]] [user]

If the ‘ -l ‘ option is included, the resulting shell session is a login shell for the specified user. This means that the user’s environment is loaded and the working directory is changed to the user’s home directory.

47
Q

sudo

A

Execute a command as another user.

48
Q

chown

A

Change a file’s owner.

49
Q

chgrp

A

Change a file’s group ownership.

50
Q

pssswd

A

Change a user’s password.

generica form: passwd [user]

51
Q

File Types

  -
  d
  l
  c
  b
A

’ - ‘ A regular file.

’ d ‘ A directory.

’ l ‘ A symbolic link. Notice that with symbolic links, the remaining file attributes are always rwxrwxrwx and are dummy values. The real file attributes are those of the file the symbolic link points to.

’ c ‘ A character special file. The file type refers to a device that handles data as a stream of bytes, such as a terminal or modem.

’ b ‘ A block special file. This file type refers to a device that handles data in blocks, such as a hard drive of CD-ROM drive.

52
Q

File Modes in Octal

  0
  1
  2
  3
  4
  5
  6
  7
A
Octal     Binary     File Mode
0            000         - - -
1             001          - - x          
2            010          - w -
3            011           - w x
4            100          r - -
5            101           r - x
6            110           r w -
7            111            r w x

^ in File Mode column, spaces added for readability: e.g. rwx becomes r w x

53
Q

CHMOD Symbolic Notation

u
g
o
a

A

’ u ‘ Short for ‘user’ but means the file or directory owner.

’ g ‘ Group owner.

’ o ‘ Short for ‘others’ but means world.

’ a ‘ Short for ‘all;’ the combination of u, g, and o.

^ if no character is specified, ‘all’ will be assumed.

54
Q

CHMOD Symbolic Notation Examples

u+x
u-x
\+x
o-rw
go=rw
u+x,go+rx
A

’ u+x ‘ Add execute permission for the owner.

’ u-x ‘ Remove execute permission from the owner.

’ +x ‘ Add execute permission for the owner, group, and world. (Equivalent to a+x.)

’ o-rw ‘ Remove the read and write permissions from anyone besides the owner and group owner.

’ go=rw ‘ Set the group owner and anyone besides the owner to have read and write permission. If either the group owner or world previously had execute permissions, remove them.

’ u+x,go+rx ‘ Add execute permission for the owner and set the permissions for the group and others to read and execute. Multiple specifications may be separated by commas.

55
Q

ps

A

Report a snapshot of current processes.

56
Q

top

A

Display tasks.

57
Q

jobs

A

List active jobs.

58
Q

bg

A

Place a job in the background.

59
Q

fg

A

Place a job in the foreground.

60
Q

kill

A

Send a signal to process.

61
Q

killall

A

Kill processes by name.

62
Q

shutdown

A

Shut down or reboot the system.