Working at the Command Line Flashcards
[cmd] pwd
print working directory - outputs the current directory that you’re in
[cmd] tty
prints the file name (because everything in linux is a file) of the terminal connected to the standard input. IE your current terminal.
Physical Terminal = tty1
Pusdo Terminal = pts/0
[cmd] who
Tells you who is logged onto the system.
[cmd] exit
logs you out of the current terminal.
[cmd] ip a s
(aka ip addr show)
prints all the current network interfaces and their IP information.
~
indicates the home directory
[cmd] ls
lists (non-hidden) files and directories in your current working dir.
NOTE: ls is aliased by default to ‘ls –color=auto”.
[cmd] ls -a
lists all files including hidden files.
[cmd] ls -F
shows the file type in the printed output. So dir files end in a / and symbolic links end in an @ and executables end in * — useful if your terminal doesnt support colors
/etc
this dir contains all the system/service configuration files.
configuration file
local file used to control the operation of a program but is static and cannot be an executable binary.
[cmd] ls -l
gives us a long listing of file types with metadata, which includes file type - permissions block - number of hard links - owner - group owner - size - date modified - name
[cmd] ls -r
reverses the order of the printed output
[cmd] ls -lrt
prints the long version, and reverses it based on time. Prints files but reversed based on time, so the oldest file will be listed first. (you can replace t with o to sort by owner)
[cmd] ls -h
puts the file size in a human readable format
[cmd] ls -d
lists the dir itself instead of the contents of the directory.
[cmd] $(cmd)
ie: ls -l $(tty)
anytime you put $() the command line will run the cmd in ()s first and then the output of that is used as the input of the other cmd.
[cmd] lsblk
lists the block devices (partitions) on the system. (which because everything is a file, these exist in the dev dir also)
[cmd] * at end
ie: ls -l /dev/sda*
wildcard character that represents 0 or more characters. ie: lists anything that follows including zero characters. so the printed result will be /sda, /sda1, and /sda2
[cmd] ? at the end
same as * wildcard but only looks at a single character. so /sda and /sda20 wouldn’t be returned.
[cmd] [12] at the end
ie: ls -l /dev/sda[12]
this is a wildcard array, so in the case of the example it would be looking for sda1 and sda2
/dev directory
this is where the device files are stored.
linux file types
- : regular file d : directory c : character device file (ie tty) b : block device (ie sda) s : local socket p : named pipe l : symbolic link
[cmd] cat
The cat command is used for:
- Display text file on screen
- Create a new text file
- Read text file
- Modifying file
- File concatenation