You get a bonus - 1 coin for daily activity. Now you have 1 coin

Unix Mini Cheat Sheet

Lecture



Unix Mini Cheat Sheet

hotkeys for fast work

Tab Autocomplete path (for folders and files) when navigating
Previous command
Ctrlc Kill executable program (Cancel)
CtrlZ Switch view from program. The commands fg, jobs, bg help manage the context
Q Exit some programs (like man-help for example)


Ctrl + Alt + T - open the Ubunutu terminal window

Alt + F2 application launch

Navigation

Now the main part is to go through the file system, whether local or remote.

ls list of files and folders
cd go to folder
pwd find out which folder I'm in
tail quick view of the end of the file (useful for logs)
cat quick file browsing
tree -d -l 2 two-level folder tree
find. -name * txt search file by name
grep "needle" file.txt pattern search
whoami find out what user I am
uname -a find out what the kernel is (and maybe the distribution)

File structure

In order to go through the file system, it is necessary to understand by what principle the tree is built, and although it is slightly different in different distributions, the FSSTND standard is like this ..

FSSTND Standard Suse 11 Mac OS 10.7 Description
boot mach_kernel Bootloader files Lilo and the image of the kernel
tmp private / tmp Temporary fails for the buta. The rest is in / var / tmp
sbin System commands needed when booting
bin Custom commands needed when booting
proc Virtual folder of kernel settings and processes
dev Connected devices
mnt Volumes Accessible through file system devices
lib Public root-level libraries
etc private / etc Machine-specific configuration files
root private / var / root Home folder of the main user
home Home folders of other users, including ftp, httpd, samba-services
usr Static files of programs, libraries, games, documentation, utilities not used when downloading
var private / var Frequently changing files - email messages, logs, temporary files
cdrom
opt +
image
lost + found
media
selinux
srv Folder for the Apache, the root of the documents instead of htdocs
net mount for NFS drives
private different folders are grouped here to restrict access
cores place to save memory dumps when falling .. can be cleaned with a lack of space
Applications All user-installed applications
Developer
Library Generally available cross-program level files (for example, fonts)
Network
System
Users home folders for real users, home extension

Combining

Convenience of Unix syntax as I already said in flexibility, namely in control characters that are used with several commands

| pipe - transfer data from one command to another, for example ls -F | grep /
; sequential launch of commands, for example date; cal
> redirect standard output to an overwritten file, for example ls / -F> list.txt
>> redirect output to file with append to end

File processing

mv renaming
rm deletion
rm -rf recursive delete
cat merge files and stream
paste line up file (s)
ln link to file or folder
split binary file sharing
join combines two files line by line
cut line by line (and / or) column cutting text from a file as from a matrix of characters
cat sequential merging of two files and output to a terminal (or file)
sort sort lines alphabetically
uniq leave unique lines

Software installation

Since * Nixes are engaged in a whole range of different tasks, hence different distributions, with their own installers.

Distributive Package Installer
Gentoo emerge
Debian. Ubunutu apt-get update
apt-get install ...
dpkg - install

The utility can be used to install the .deb package with the command:

  dpkg -i package_name.deb 
Fedora rpm -ivh ...
yum -y install ...
Look also at possible repositories.
Mandriva urpm
Slackware yast zypper
gzip, lzma

In addition to the system general installers, there are specific installers for specific needs.

  • port install mongodb - macports installer
  • pear install phpunit / PHPUnit
  • pecl install mongo
  • gem

Text editors

Vi Vim Nano Gedit Mate Pico Emacs
Ubuntu + + + -
Mac os lion + + - + + +
Debian 5 + + + - + -
Suse 11 + - - - - -

vi readme.txt
i - edit mode
esc - access to general mode
ZZ - save and exit
"- console mode
! q - exit without saving
wq - output with a record

Archivers

gunzip unzip .gz
bunzip2 unzip .bz2
tar -jxvf unpack .tar

Processes and diagnostics

top running processes See also htop, pstree
netstat open connections
for example open ports in Linux: netstat -atp | grep -i "listen" or netstat -tupl
on the Mac: lsof -n -i4TCP | grep LISTEN
lsof open files (for example open ports in a poppy: sudo lsof -i -P | grep -i "listen")
killall kill the process by name. Sometimes you have to kill pointwise (for example, suspended mysql) by PID:
kill -9 1566
whereis hint where process files are located
df -h report on free HDD-memory (in readable form). To find large files on the server:
find. -type f -size + 50000k -exec ls -lh {}; | awk '{print $ 9 ":" $ 5}'
w list of users at the moment
opensnoop tracking file pointer access

Work with servers

Practically all constantly working programs - demons are in / etc / init.d / and have the start, stop, restart commands. Root rights are required to manage them. In some cases (Fedora) may have to use / sbin / service to access them.

ssh Remote connection
scp Secure network copy over SSH from one server to another. The -r flag makes recursive copying of folders. For example:
scp -r root@example.com:/srv/htdocs/ /home/html_sources/
ab (Apache Bench) - load testing (for example, with -r -c 100 -n 1000 parameters)
nc (netcat) - direct socket connection
rsync Synchronize rsync -av -e ssh --progress /local/source user@example.com:remote/target files rsync -av -e ssh --progress /local/source user@example.com:remote/target
Apache

On the Mac, Apache2 is built in (enabled in the sharing settings) and it makes sense to enable .htaccess (see the AllowOverride directive)

Linux Mac osx
Launch /etc/init.d/httpd restart / etc / init.d / apache2 restart / etc / apache2 /
/ usr / sbin / apachectl restart
/private/etc/apache2/httpd.conf/private/var/log/httpd/access_log
Logs / private / var / log / apache2 / access_log
/ private / var / log / httpd / access_log
Php
Suse 11 Mac osx
/etc/php5/apache2/php.ini
/ usr / share / php5 /
/ usr / lib64 / php5 /
/private/etc/php.ini
/ usr / local / php5 / lib / php / extensions /
Mysql

MySQL's default settings are wired (you can ask mysqladmin to look at them), to overwrite your own, you need to put a my.cnf file in / etc (there is a sample in the support-files folder). The most useful utilities in the bin folder are mysql (direct console access to the server) and mysqldump (for migrating large databases).

If you are sitting on a Mac, but you want to use sqlyog through a virtual machine, you can share the connection ..

CREATE USER 'your_user_id'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL ON your_database_name.* TO your_user_id@'%' IDENTIFIED BY 'your_password';

When you work quickly with the server itself, the commands most in demand

SHOW PROCESSLIST;
SHOW DATABASES;
CHECK TABLE;
REPAIR TABLE;

Control daemon

Linux Mac osx
/etc/init.d/mysql restart / usr / local / mysql / bin / mysqld_safe
/ usr / local / mysql / bin / mysqladmin shutdown

Comments


To leave a comment
If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

LINUX operating system

Terms: LINUX operating system