Linux in around 90 (so far) bullet points. Ubuntu Edition
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) http://creativecommons.org/licenses/by-nc-sa/4.0/
- Directory structure
- Basic commands
- Files
- Users
- Applications
- Security
- Process management
- Text processing
pwd
prints current/working directorysudo <command>
in general: to execute a<command>
as an other user (e.g. root), usually: executes a command as a superuser (a.k.a. root)su [<user>]
to become, for the login session, a different user, if<user>
is not providedsu
defaults to becoming the superuser.
touch <file>
creates a new<file>
or updates modification time if<file>
already existsmkdir <directory>
creates a new<directory>
rm <file>
removes a file-d
removes a directory (if it's empty)-r
removes recursively (also removes directories)-f
ignores problems like nonexistent files, never asks about anything-i
asks before every removal (paranoid mode)-I
asks before removing more than 3 files or when removing recursively (safe but not paranoid)ln <target> <link_name>
creates a link of name<link_name>
to the<target>
-s
the link is symbolic (soft), that's usually what you want, especially if you link to a directorycp <source> <destination>
copies<source>
file to the<destination>
file-a source/. destination/
copies all files from thesource
directory to thedestination
directory (preserves folder structure, symbolic links, etc.)mv <source> <destination>
moves<source>
file to the<destination>
directory or file, e.g.mv file1 file2
basically just renamesfile1
intofile2
,mv file1 directory
movesfile1
to thedirectory
,mv file1 directory/file2
movesfile1
into thedirectory
and renames the file tofile2
-f
doesn't ask if some file gets overwrittenls [<directory>]
lists files in the current or in the specific directory-l
long list format (more details)-a
also lists files which name starts from dot ("hidden" files)-h
file size in human readable format (e.g.4.0K
instead of4096
)find
searches for files in the directory treefind -name '<pattern>'
- look for a file which name meets the<pattern>
(e.g.find -name '*.html'
orfind -name 'id_rsa*'
)find <directory> -name '<pattern>'
- look for a file with<pattern>
name in the<directory>
grep '<pattern>' [<location>]
- search for a<pattern>
within a<location>
.<location>
can be either a file, a directory or a standard input. User can provide as many<locations>
as she wants.--include <file-name-pattern>
- search only within files whose name matches the<file-name-pattern>
. E.ggrep --include *.html "div"
looks for an occurence ofdiv
inhtml
files in the current directory.-r
searches recursively through the directories-P <perl-regex>
uses Perl regular expression for a search pattern (for Perl/PHP lovers)-E <extended-regex>
uses "extended" regular expression for a search pattern, same asegrep
-n
shows line number along the result-A <number>
in addition to the line where<pattern>
was found also shows a<number>
of lines after-B <number>
additionaly shows a<number>
of lines before the one where<pattern>
was found-L
shows files that don't contain searched<pattern>
cat /etc/passwd
to list all users (cut -d: -f1 /etc/passwd
to just see their names)adduser <username>
adds a new user with name<username>
(will also ask you to provide a password for that user)adduser <username> <groupname>
specifies to which group user should be added (or if user already exists adds<username>
to the<groupname>
)--system
to add a system useradduser <username> sudo
adds user to the groupsudo
and to thesudoers
file (/etc/sudoers
). This lets the user executesudo
command.addgroup <groupname>
adds a new user groupdeluser <username>
removes a user--remove-home
removes user's home directory (/home/<username>
)--remove-all-files
removes all files owned by the user--backup
backup files before removing--system
if user is a system userdeluser <username> <groupname>
removes a user from a group (user still exists)groups <username>
list groups user with<username>
is member of- when you add new user it's good to check to which groups typical user belongs to and add new user to them to
delgroup <groupname>
removes a group--only-if-empty
only remove the group if there are no users in it
which <application>
tells where the<application>
is located, e.g.which grep => /bin/grep
apt-get install <package>
installs<package>
from the repositoryapt-get remove <package>
uninstalls<package>
apt-get purge <package>
likeremove
but also deletes configuration files, etc.apt-cache search <keyword>
searches apps/packages by<keyword>
apt-cache show <package>
shows info about app/package (e.g. version and size)apt-add-repository <repository>
adds<repository>
to the lists of repos (located under/etc/apt/sources.list
or/etc/apt/sources.list.d
-r
removes repo from the list
- to disable root SSH login: open
/etc/ssh/sshd_config
, find (or add, or uncomment) a settingPermitRootLogin
, set it tono
and restartssh
service (service ssh restart
) - to allow a user executing
sudo
without apassword
(bit risky, but useful when user logins using public/private keys): sudo visudo
- add line
<username> ALL=(ALL) NOPASSWD: ALL
- port scanning, port blocking, firewall rules, honeypots...
- top, kill, etc.
tail <file>
shows the last part of the<file>
(last 10 lines)-f
outputs the appended data as the file grows ("live update")-n <number>
how many lines should be shown- can show output from many files at once, e.g.
tail /var/log/*/*.log
ortail file1 file2
vim <file>
opens a<file>
in the vim editor (orvim
to just open vim)i
(when inside vim) switches from visual mode to edit mode (other ways:a
,I
,A
)<Esc>
to switch from either visual or edit mode into a command mode- Notable
vim
commands: u
undo (Ctrl+R
redo)/<search_pattern>
searches for a<search_pattern>
n
go to the next search resultN
go to the previous search result:e <file>
opens a<file>
:q
quits vim:w
save (write):wq
save and quit:q!
quit without savingcat <file>
shows the content of the<file>
-n
with line numbers- can show content of many files at once, e.g.
cat /*.txt
orcat file1 file2
- less, nano