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
pwdprints 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 providedsudefaults 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-dremoves a directory (if it's empty)-rremoves recursively (also removes directories)-fignores problems like nonexistent files, never asks about anything-iasks before every removal (paranoid mode)-Iasks 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>-sthe 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 thesourcedirectory to thedestinationdirectory (preserves folder structure, symbolic links, etc.)mv <source> <destination>moves<source>file to the<destination>directory or file, e.g.mv file1 file2basically just renamesfile1intofile2,mv file1 directorymovesfile1to thedirectory,mv file1 directory/file2movesfile1into thedirectoryand renames the file tofile2-fdoesn't ask if some file gets overwrittenls [<directory>]lists files in the current or in the specific directory-llong list format (more details)-aalso lists files which name starts from dot ("hidden" files)-hfile size in human readable format (e.g.4.0Kinstead of4096)findsearches 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 ofdivinhtmlfiles in the current directory.-rsearches 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-nshows 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-Lshows files that don't contain searched<pattern>
cat /etc/passwdto list all users (cut -d: -f1 /etc/passwdto 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>)--systemto add a system useradduser <username> sudoadds user to the groupsudoand to thesudoersfile (/etc/sudoers). This lets the user executesudocommand.addgroup <groupname>adds a new user groupdeluser <username>removes a user--remove-homeremoves user's home directory (/home/<username>)--remove-all-filesremoves all files owned by the user--backupbackup files before removing--systemif 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-emptyonly remove the group if there are no users in it
which <application>tells where the<application>is located, e.g.which grep => /bin/grepapt-get install <package>installs<package>from the repositoryapt-get remove <package>uninstalls<package>apt-get purge <package>likeremovebut 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.listor/etc/apt/sources.list.d-rremoves repo from the list
- to disable root SSH login: open
/etc/ssh/sshd_config, find (or add, or uncomment) a settingPermitRootLogin, set it tonoand restartsshservice (service ssh restart) - to allow a user executing
sudowithout 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)-foutputs 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/*/*.logortail file1 file2 vim <file>opens a<file>in the vim editor (orvimto 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
vimcommands: uundo (Ctrl+Rredo)/<search_pattern>searches for a<search_pattern>ngo to the next search resultNgo to the previous search result:e <file>opens a<file>:qquits vim:wsave (write):wqsave and quit:q!quit without savingcat <file>shows the content of the<file>-nwith line numbers- can show content of many files at once, e.g.
cat /*.txtorcat file1 file2 - less, nano