Useful commands Linux

In the future, using the website cloudhosting.lv, you agree to the rules of using Cookies. Read more. I agree

Useful commands Linux

Some tasks may require the skills of working with the Linux command line. This is easy enough if you know the basic commands which Linux -server understands.

Interaction with the server takes place via SSH protocol, so if you are running Microsoft Windows, you will need to install a program to work with SSH (Linux and Mac OS doesn’t require additional installations):

  • PuTTY - free program for working with SSH, which doesn’t require installation.
  • ExtraPuTTY - an enhanced version of PuTTY.
  • SecureCRT - a powerful program to work with SSH (supports many other protocols).

Keyboard shortcuts

  • Ctrl + C - stops the current command.
  • Ctrl + D - log out (similar to exit).
  • exit - log out.
  • Ctrl + W - erases one word in the current line.
  • Ctrl + U - delete line.
  • !! - Repeat the last command.

Other useful commands

Upload file to server:

wget http://www.cloudhosting.lv/filename.zip

Processes list:

top

Processes list of a certain user:

top –u user-name

Currnet date:

date

Change password:

passwd

Change password of a certain user:

passwd user-name

Show information about core:

uname -a

Show information about CPU:

cat /proc/cpuinfo

Show information about memory:

cat /proc/meminfo

Show information about disc usage:

df

Restart certain service:

/etc/init.d/service-name restart

Information about memory usage and swap:

free

Possible application location:

whereis application-name

Server restart (full reboot):

Reboot

Archiving / Unzipping

Create tar.gz-archive:

tar czf archive-name.tar.gz directory-name 

Unpack the tar.gz-archive:

tar xzf archive-name.tar.gz 

Create tar.bz2-archive:

tar cjf archive-name.tar.bz2 directory-name 

Tar.bz2-unpacking archive:

tar xjf archive-name.tar.bz2 

Unpack the rar-archive:

unrar x archive-name.rar

Working with files and folders

List of files and folders:

ls 

Full list of files and folders, including hidden:

ls -a 

Change directory:

cd directory-name

Examples of use:

  • cd / - move to the root directory of the disk;
  • cd .. - move to the upper directory;
  • cd ../ .. – move to the 2 upper directories;
  • cd $ HOME - move to the home directory (just enough to type cd);
  • cd /home/folder-name/subfolder-name - go to the specified folder.

Create folder:

mkdir folder-name

Delete folder or file:

rm file-name

Delete files and folders recursively (including all attached files and folders):

rm -r folder-name

Copy file:

cp file-name copy-file-name

Copy folder:

cp -r folder-name copy-folder-name

Rename file:

mv file-name new-file-name

If «new-file-name» — is a folder, file will be moved to its folder.

Create symbolic link:

ln -s file-name link-name

Change permission (CHMOD) to file or folder:

chmod 755 folder-name

Change permission (CHMOD) to all files recursively:

find . -type f | xargs chmod 644

Change permission (CHMOD) to all files with specific extension recursively:

find . -name '*.cgi' -type f | xargs chmod 755

Change permission (CHMOD) to all folders recursively:

find . -type d | xargs chmod 755

Data base backup

Data base backup with mysqldump (command must be in one line):

mysqldump --user=USERNAME --host=HOST -acnqQ --single-transaction
--default-character-set=ENCODING --password=PASSWORD -- DATA_BASE
| sed "s#^CREATE TABLE#� IF NOT EXISTS# ; s#^INSERT INTO#REPLACE INTO#"
| gzip -qf9c > /home/username/directory-where-backups-will-be-stored/data-base-name-
`date +%Y-%m-%d`.sql.gz

Encoding example: cp1251, utf8.


Working with Perl

Performing Perl-script:

perl script-name.cgi

Perl module installation through CPAN:

install MODULE: :NAME

Before doing this you must enter into CPAN, entering next command:

perl -MCPAN -e "shell"