Sie sind auf Seite 1von 1

Livre Digital A little survival guide to command line

Livre Digital, all rights reseved


c 2017.
We focus our business,
Livre Digital Team Licence: Creative Commons Attribution - Share ALike 4.0
in open source solutions.
https://creativecommons.org/licenses/by-sa/4.0/legalcode
info@livredigital.com
http://www.livredigital.com
https://www.livredigital.com

this is a survival guide to all unix users of the world, specially the new ones; this poster have quick tips to use in your day to day life on linux, osx, *bsd.

Top 10 most necessary commands The VI / VIM editor UNIX Directory Structure Tree
+ description example /
The VI editor is probably the most used editor in UNIX systems, it comes with There are many others commands in VI, some of these starts with colons (:),
pwd print working directory $ pwd
almost any distribution of Linux, *BSD and can be also used in OSX. The editor here are some of the most used in our opinion:
cd change directory $ cd ..
comes with two main modes: command and insertion. command description /bin /dev /etc /home /lib /sbin /var
ls list files $ ls -a *.txt
cp copy files $ cp -rf /dir /opt/subdir :w, :wq (w)rite file, (w)rite file and (q)uit file.
The insertion mode is commonly to all users, you just type something and text :q, :q! quit file, or quit file without change anything
mv move files $ mv oldfile newfilename /etc/passwd /etc/nginx /var/log /var/run
typed will be into file, the command mode is accessed by hotkey [ESC] :!gcc file.c executes gcc to compile file.c into ./a.out binary
touch creates new file $ touch file1 file2
mkdir creates a directory file $ mkdir -pv /tmp/dir/subdir hotkey description :r !date read the output of command date and puts on file
h, j, k, l move cursor left, down, top, right respectively :set number show line numbers at left /var/log/nginx
rm remove files $ rm -f /tmp/file
echo echoes a line $ echo ”hello world” > file.txt 0, $ move cursor to the beginning and end of line respectively :5,20d delete lines 5 - 20 dir description
u, [ctrl] + r (u)ndo last and redo last change respectively :%s/old/new/g replaces all occurrences of old to new string / root directory /lib libraries and kernel modules
cat concatenate/print files $ cat /etc/passwd

o m
255G, G go to line 255, go to last line respectively

c
i, o go to (i)nsert mode, insert on next line respectively
:help cmd get help about cmd
:vimtutor starts the tutorial mode for learning vi
/bin binary files
/dev device and peripheral
/opt optional softwares
/sbin super binary files

$ cd
Working with files and directories
go to the user home directory
a l . /etc system config files
/home users directory
/usr programs shareable content
/var temporary/log files
$ cd /etc
$ cd /etc/nginx
enter in the directory etc of /
enter in the directory nginx of /etc
$ dmesg
g i t Basic Systems and Network Management Commands

display system messages from kernel $ ping livredigital.com pings a hostname or ip


Structured hierarchy directory;
$ cd ..
$ ls /tmp/*.txt
comes back one level up to /etc
list all .txt files in /tmp
$ fdisk
$ fsck /dev/sda

e d i
manage disk partitions table
check and repair filesyste, /dev/sda
$ ifconfig -a
$ route -n
show interface(s) network information
displays, add and del gateway on network
Everything is a file and they are case sensitive;;

UNIX Permissions
$ ls -a /home/user
$ cp file1 copyfile
$ cp file1 file2 /tmp
list all hidden files of /home/user
copies a single file
copies multiple files to /tmp
$ groupadd dev
$ lsmod

i v r
creates dev group (groupdel removes)
list all modules loaded by kernel
$ iptables -L -n -v display the firewall rules
$ traceroute google.com display the nr of hops to reach google
$ cd /etc; ls -lhd passwd profile* rc.local resolv*
(list passwd, rc.local and all other files starting by prefix ’profile’ and
$ cp file1 copyfile
$ cp -r ./dir1/ /tmp
copies a single file
copies recursively dir1 to /tmp
$ mkswap /tmp/file

w . l
$ mkfs -t ext4 /dev/disk format /dev/disk with ext4 fs
setup a swap area for use
$ netstat -nap
$ dig livredigital.com
display (A)LL socket connections
query all DNS records for host
’resolv’)

$ mv oldfile newname
$ mv file1 file2 /tmp
renames oldfile to newname
moves file1 and file2 to /tmp
$ rm -f /tmp/share.txt removes share.txt from /tmp dir
$ passwd billy

w
$ shutdown (-r/-h) now
$ umount /mnt
w
$ mount /dev/sdc1 /mnt maps device /dev/sdc1 on /mnt
modifies the password of user billy
reboot, halts the system at specified time
unload the device mapped on /mnt dir
$ host google.com
$ whois domain.com
$ tcpdump -i eth0 -vv
$ nc 10.0.0.1 25
get the ip address of host
get the registry records for domain
sniff all packets of eth0 interface
a really powerful tool for network test
-rw-r–r–
-rw-r–r–
1 root root
1 root root
drwxr-xr-x 2 root root
1.9K May 24 18:43 passwd
761 Oct 22 2014 profile
4.0K Feb 10 17:56 profile.d
$ rm -rf /tmp/lz0 removes lz0 subdir from /tmp dir -rwxr-xr-x 1 root admin 306 Feb 10 17:49 rc.local
$ useradd joe add user joe to system (userdel removes) $ ssh root@google.com remote connect on console of a network host
$ head -n 20 file.txt shows first 20 lines of file.txt -rw-r–r– 1 root root 935 May 12 23:41 resolv.conf
$ tail file.txt shows last 10 lines of file.txt Distribution Package Management - Search, Installs, Remove Packages
$ ls -l rc.local
$ less file.txt shows contents of file.txt pagined
-rwxr-xr-x 1 root admin 306 Feb 10 17:49 rc.local
Red Hat Linux - YUM and RPM Debian GNU/Linux
Process Management, Modifying, Compressing, Archiving
process management description example description example
$ top interactive display of processes yum the yum software package manager apt-get the apt software package manager
$ ps aux show all users processes of system update metadata of repository # yum update update metadata of repository # apt-get update
$ kill -9 10002 kill a process id (PID) number 10002 upgrade all packages # yum upgrade upgrade all installed pkgs # apt-get upgrade
$ nice -n -10 2553 give a better priority for pid 2553 search for vim rpm on repository # yum search vim install dependencies and the package # apt-get install vim
(de)compression c: create; t: contents; j: bzip; z: gzip
install dependencies and the package # yum install vim apt-cache browse packages on repository
x: extract; v: verbose; r: recursive rpm red hat package manager show basic information of a pkg # apt-cache show pkgname
$ tar cvfz /usr /var file.tar.gz compress /usr and /var into file.tar.gz install a rpm package # rpm -ivh file.rpm show dependencies of pkgname # apt-cache depends pkg
$ tar xfj file.tar.bz2 -C /opt extract file.tar.bz2 into /opt list all rpm’s installed on system # rpm -qa search for ncurses .deb on repository # apt-cache search ncurses
$ zip -r /tmp temporary.zip compress /tmp dir into temporary.zip shows the rpm package relative to file # rpm -qf /usr/bin/ls dpkg debian package manager
$ gzip /var/log/messages compress messages file into .gz shows file contents of package # rpm -ql file.rpm install a deb package # dpkg -i file.deb
remove redhat package # rpm -ev file.rpm $ chmod ug+wx rc.local
install source files list all deb’s installed on system # dpkg -l
change permission to (u)ser, (g)roup of (w)rite and e(x)ecute
$ ./configure && make check dependencies, build software remove a deb’s installed package # dpkg -r file.deb
$ chmod o-rwx rc.local
$ make install install software for all users shows the contents of deb package # dpkg -c file.deb
removes all permissions (read, write, execute) to any other user/group

Livre Digital Team A little survival guide to command line

Das könnte Ihnen auch gefallen