Take control of Linux Flashcards
$ sudo [command]
For every command that requires root permission.
$ sudo su
Same as putting sudo in front of a command.
$ pwd
print working directory , or “where I am”.
$ ls
List the content of the current directory.
$ ls -a
List the content of the working directory, including hidden files.
$ cd [directory]
Change the current directory.
$ cd ..
Move to parent directory of current directory.
$ mkdir [directory]
Create a directory.
$ cp [source] [destination]
Copy and paste a file.
$ mv [source] [destination]
Move (rename) a file or directory.
$ cp -r [source] [destination]
$ Copy and paste a directory.
$ rm [file]
Remove file.
$ rm -rf [directory]
Recursive removal of directory.
$ cat [file]
cat means “concatenate”. View the content of a file.
$ cat [file] [file]
View the content of multiple files.
$ cat >[file]
Create a file.
$ cat [file1] > [file2]
Redirect standard output of file1 into new file2. Existing content of file2 will be overwritten.
$ cat [file1] >> [file2]
Append standard output of file1 into file2, without overwritting.
$ cat < [file]
Output of the file will be shown in terminal.
$ cd (or $ cd ~)
Navigate to home directory.
$ cd /
Navigate to root directory.
$ cd -
Navigate to previous directory.
$ ln -s [target] [source]
Create a symbolic link at [source] referencing the original file [target].
What is a symbolic link?
Also called soft link or symlink, it can be thought of as a shortcut to a file or directory.
$ stat [file_or_dir]
Display file status.
$ stat -c %a [file_or_dir]
Display access rights in octal (numeric) of file.
What are the different classes of users for file access?
owner: #– or -###—— group: -#- or —-###— other: –# or ——-###
What are the different permissions for file access?
read: 4 or r write: 2 or w execute: 1 or x
How to change permissions with letters? Example: add other & execute.
+: add permission. -: remove permission. =: set permission. Example: chmod o+wx [file]
$ ls -l [file]
Display access rights of file in letters.
How to change permissions with numbers? Example: -rw-rw-rwx.
Add the value of each permissions you want to set for each group. Example: owner: 4+2=6 group: 4+2=6 other: 4+2+1=7 $ chmod 667 [file]
$ sudo chown [username]:[group] [directory]
Change the ownership of both the user and the group for this directory.
$ sudo chown -R [username]:[group]
Change the ownership of both the user and the group of all files and directories within this directory.
How to make root the only user able to write the file?
$ sudo chown root:root [file] $ sudo chmod 700 [file]
What is the command apt-get?
apt is one of the tools used to interact with the APT (Advanced Packaging Tool) to install, remove and manage packages in Debian-based Linux distributions.
What is the command apt?
apt consists of some of the most widely used features from apt-get and apt-cache leaving aside seldom used features. It is considered more secure to use apt.
$ tail [file]
View the last 20 lines of a file.
$ tail -n [number]
View an arbitrary number of the most recent files.
$ tail -f [file]
Follow a file as more lines get appended to it.
$ apt-get update
Update the list of available packages and their versions, but do not install or upgrade any package.
$ apt-get upgrade
Actually installs newver versions of the packages. To be used after having updated the package lists.
$ apt-get install [package]
Install a new package.
$ apt-get check
Does an update of the package lists and checks for broken dependencies.
$ apt-get autoclean
Removes .deb files for packages that are no longer install on the system.
$ apt-get clean
Remove all packages from the package cache (more powerfull than apt-get autoclean).
$ apt-get remove [package]
Removes an install package, leaving the configuration file intact.
$ apt-get purge [package]
Completely removes an installed package and the associated configuration files.
$ apt-get autoremove
Remove packages that were installed by other packages and are no longer needed.
$ apt-cache search [search_term]
Lists packages whose name or description matches search term.
$ apt-cache show [package]
Shows description of package as well as version, size, dependencies and conflicts.
$ man apt-get (or apt-cache or dpkg)
Shows the manual associated with these tools.
With apt-get, for what the -s flag is used for?
To simulate an action. Example: apt-get -s install [package] will simulate installing the package, showing what will be installed and configured.
What is Zsh?
An alternative shell to the traditional Bash (Bourne Again Shell) with syntax highlighting, tools integration and plugins.
chsh -s /bin/zsh
Make Zsh the default shell.
What are two popular plugin managers for Zsh?
oh-my-zsh and zprezto.
What is tmux? What is it usefol for?
tmux is a terminal multiplexer, allowing a user to access multiple separate terminal sessions inside a single terminal window or remote terminal session. It is useful for dealing with multiple programs from a command-line interface, and for separating programs from the Unix shell that started the program.
$ tmux
Start a tmux session.
How are commands triggered in tmux?
By a prefix key (C-b or Ctrl+b) followed by a command key.
C-b %
Split a tmux pane into a left pane and right pane.
C-b “
Split a tmux pane into a top pane and bottom pane.
C-b
Navigate panes in tmux.
$ exit or C-d
Close a pane in tmux.
C-b c
Create a new window in tmux, similar to creating a new virtual desktop.
C-b p / C-b n
Navigate to previous or to next window in tmux.
C-b
Navigate to a specific window in tmux, given its number.
C-b d
Detach current session in tmux and leave it running in the background for later reuse.
$ tmux ls
Figure out which sessions are running in the background, possibly to attach to them.
$ tmux attach -t [number]
Attach to a tmux session with a given number.
$ tmux new -s [name]
Start a tmux session with a given name.
$ tmux rename-session -t [old number or name] [name]
Rename a tmux session.
What does it mean that the text editor Vim is modal?
The actions we can perform in Vim depends of the mode we are using.
What are the 3 modes of Vim?
Insertion mode: similar to a classic editor, the text typed is inserted where the cursor is. Normal/Command mode: enable text navigation, copy-pastes, deletions… Visual mode: enable text selections.
What is a Vim plugin managers and some of its absolutely necessary plugins?
Plugin manager: Vundle. Plugins: NERDtree (file hierarchy), ack (search for a character chain), CtrlP (fuzzy search of files), Surround (add/modify quotes, double quotes, parentheses…)
$ vim [file]
Edit a file or create a new file if it does not exist yet.
In Vim: i
Enter insertion mode before the current position.
In Vim (insertion): ESC
Enter command mode.
In Vim: :wq
Save the file (Write) and then quit Vim.
In Vim: :q!
Quit and discard changes.