Linux Flashcards
(38 cards)
sudo !!
Runs the previous command, with sudo
.
In general, the two exclamation marks refer to the previous command you just ran.
cd -
Returns to the previous working directory
pushd
popd
pushd
changes into the new directory and pushes the current working directory to a stack.
popd
brings one of the items out of the stack and changes into it
ctrl + z
fg
ctrl + z
sends an app to the background, effectively minimizing it.fg
brings that app out.
ctrl + r
Searches through the commands previously ran. Pressing ctrl + r
again will go to the next best match.
history
Shows the command history.
!
Runs a previously ran command from history. In the Linux world, the exclamation mark is often referred to as bing
.
HISTCONTROL=ignoreboth
If you assign ignoreboth
to this variable, your can prevent commands from showing up in history by adding a space in the beginning,
HISTTIMEFORMAT=”%Y-%m-%d %T “
If you assign “%Y-%m-%d %T “ to this variable, commands stored in the history will have a specific time assigned to them. This could be placed in .bashrc
. The space at the end is for formatting.
cmatrix
A package and a command to show a Matrix-inspired screen saver sort of thing.
ctrl + u
Clears the line.
ctrl + a
Puts the cursor all the way to the front of the line.
ctrl + e
Takes the cursor to the end of the line.
What is the difference between changing commands with ;
and &&
?
When you chain commands with a semicolon, all the commands will run even if one or more of them fail.
On the other hand, when you chain commands with the double ampersand, if it encounters an error it will not run subsequent commands.
tail -f
Shows the content of a file (a log file for example) and updates if anything new is added to the file.
truncate -s 0
Sets the size of a file. If 0 is provided as the first argument, it will empty the file.
column -t
Creates columns out on output. For example mount | column -t
.
Basic data streams in Linux
Standard output (stdout) and 1 is the number designation Standard input (stdin) 0 Standard error (stderr) 2
echo $?
Gives us the return code for the previous command.
0: success
Anything else is considered an error.
find /etc -type f 2> /dev/null
The find command is obvious.
What 2> /dev/null
does is, it redirects all the errors to another file and prevents them from showing up in the output.
The >
symbol is the redirect operator and it will override the file.
But if you use >>
the output will be added to the end of the file.
2 is the designation number for stderr. If you don’t have a number designation, the default is 1 (which is stdout).
/dev/null
is essentially a black hole, anything sent there will be lost forever.
set -x
Prints out all the commands running for calculating the prompt.
After running that, run exec 2>zsh.err
to get stderr into a file.
grep –files-without-match “git” ~/.oh-my-zsh/themes/*
Shows file names that do not match a string.
yes
prints a lot of output
Effectively taking up all the resources
ps
Shows the running processes as part of this particular terminal session
The response is a table with the following format:
PID: the process id
TTY: the terminal that the process is running in. If the process is running as a part of a terminal, it’s going to show here. Otherwise it’s going to show a question mark.
TIME: how much time has the process been utilizing the CPU
CMD: the actual command that is running as part of that process