Académique Documents
Professionnel Documents
Culture Documents
http://www.tutorialspoint.com/unix/index.htm
Linux Keyboard Shortcuts
1. Useful Command Line Keyboard Shortcuts
The following keyboard shortcuts are incredibly useful and will save you loads of time:
Just so that the commands above make sense, look at the next line of text.
sudo apt-get install programname
if I have a spelling error and for the command to work I would need to change "intall" to "install".
Imagine the cursor is at the end of the line. There are various ways to get back to the word install to change it.
I could press ALT + B twice which would put the cursor in the following position (denoted by the ^ symbol):
sudo apt-get^intall programname
Now you could press the cursor key and insert the ''s' into install.
Another useful command is "shift + insert" especially If you need to copy text from a browser into the terminal.
2. SUDO
sudo
Solution to the words "permission denied" appear. How do you use sudo? Simply imagine you have entered the following command:
apt-get install ranger
The words "Permission denied" will appear unless you are logged in with elevated privileges.
sudo runs the previous command as sudo. So the previous command now becomes:
sudo apt-get install ranger
If you don't know what sudo is start here.
So what is this tip about? Imagine you have opened a file in nano as follows:
sudo nano abc.txt
Halfway through typing text into the file you realize that you want to quickly type another command into the terminal but you can't because nano
is opened in foreground mode.
You may think your only option is to save the file, exit nano, run the command and then re-open nano.
All you have to do is press CTRL + Z to pause the foreground application and be returned to the command line. You can then run any command
you like. To return to the paused session entering "fg" @ terminal + return.
An interesting thing to try out is to open a file in nano, enter some text and pause the session. Now open another file in nano, enter some text and
pause the session. If you now enter "fg" you return to the second file you opened in nano. If you exit nano and enter "fg" again you return to the
first file you opened within nano.
Many date and time formats check the man pages for more ways to use 'at'.
The command line window will be much like any other file manager but it works left to right rather than top to bottom meaning that if you use
the left arrow key you work your way up the folder structure and the right arrow key works down the folder structure. It is worth reading the man
pages before using ranger so that you can get used to all keyboard switches that are available.
shutdown -c
Note that if the shutdown has already started then it may be too late to stop the shutdown.
Another command to try is as follows:
pkill shutdown
Process Management
ps Display your currently active processes
top Display all running processes
kill pid Kill process id pid
killall proc Kill all processes named proc (use with extreme caution)
bg Lists stopped or background jobs; resume a stopped job in the background
fg Brings the most recent job to foreground
fg n Brings job n to the foreground
Installation from source
./configure
make
make install
dpkg -i pkg.deb install a DEB package (Debian / Ubuntu / Linux Mint)
rpm -Uvh pkg.rpm install a RPM package (Red Hat / Fedora)
Stopping & Starting
shutdown -h now Shutdown the system now and do not reboot
halt Stop all processes - same as above
shutdown -r 5 Shutdown the system in 5 minutes and reboot
shutdown -r now Shutdown the system now and reboot
reboot Stop all processes and then reboot - same as above
startx Start the X system
%disk commands
blkid
fdisk
parted
lsblk
df
Recommended reading:
Cheat-Sheets.org All cheat sheets, round-ups, quick reference cards, quick reference guides and quick reference sheets in one page. The only
one you need.
Tutorial: The best tips & tricks for bash, explained Linux Tutorial Blog / Quality Linux tutorials without clutter
LinuxCommand.org Learning the shell, Writing shell scripts, Script library, SuperMan pages, Who, What, Where, Why
LinuxManPages.com General commands, System calls, Subroutines, Special files, File formats, Games, Macros and conventions, Maintenence
commands, Most Popular Man Pages
Linux Man Pages from die.net Man pages are grouped into sections, to see the full list of Linux man pages for a section, pick one. Or you can
browse Linux man pages by name; choose the first letter of the name of the Linux command, function, or file you are interested in.
Linux Newbie Guide: Shorcuts and Commands Linux essential shortcuts and sanity commands; Common Linux commands - system info;
Basic operations, network apps, file (de)compression; Process control; Basic administration commands, accessing drives/partitions; Network
administration tools, music-related commands, graphics-related commands.
Sudo Manual Pages Sudo (su "do") allows a system administrator to delegate authority to give certain users (or groups of users) the ability to
run some (or all) commands as root or another user while providing an audit trail of the commands and their arguments. For more information,
see the introduction to Sudo. Sudo is free software, distributed under an ISC-style license.
Navigation
Find out kernel driver module bttv configuration file name, so that you can remove the driver:
# grep -R "bttv" /etc/* | less<
The strings Commands
The grep command is useful to search a text file, if you would like to find text string in a binary file then use strings command.
# strings /usr/bin/users
You might think this is stupid idea to search inside binary file for text string. Well, no it is not a stupid idea. For example, you would like to
quickly find out if internet service supports tcpd access control facility via /etc/hosts.allow and /etc/hosts.deny files (read as tcp wrappers) or not.
Let us find out if sshd server support tcpd or not:
# strings $(which sshd)| grep libwrap
libwrap.so.0
libwrap refuse returns
The find Command
Use find command to find the files. Find all files belonging to the user charvi:
# find / -user charvi
Remove all core dump files
# find / -name core -exec rm -i{}\;
Please see more find command examples here and here. For more info please read the man pages of find, grep, file, which.
In windows OS programs are installed using executable software. In a virtual environment this is not
possible, thus the need for package managers.
You can apply knowledge of Red Hat Enterprise Linux or Fedora to Ubuntu. The key differences are:
Administrative Tasks
By default In Red Hat Enterprise Linux and Fedora, each administrative user must know the root password, and their own password. In Ubuntu,
each user only has one password. Users - admin group can run command line and graphical applications with elevated privileges. Graphical
admin tools prompt for this password when run, and command line tools can be run with root-privileges using sudo.
Package Management
Ubuntu has more packages available than Fedora, so there is a better chance of finding repositories you want. As with Fedora graphical
applications link into the Applications menu.
Graphical Tools
The Synaptic package Manager is an excellent tool for finding, fetching and installing packages. Press System -> Administration -> Synaptic
Package Manager to start Synaptic.
Command Line Tools
Ubuntu uses apt-get instead of yum, or up2date to find, download, and install packages and their dependencies. Note that, unlike yum (uses rpm),
apt-get is only for packages available in repositories (therein sources.list) - it cannot handle packages you have already downloaded but the dpkg
command can.
Task
Red Hat/Fedora
Ubuntu/Debian
apt-get update
Remove a package
rpm -e package_name
yum check-update
apt-get -s upgrade
apt-get -s dist-upgrade
Upgrade packages
yum update
rpm -Uvh [args]
apt-get upgrade
yum upgrade
apt-get dist-upgrade
Package Information
apt-cache dumpavail
dpkg --list
apt-cache depends
apt-cache rdepends
apt-cache stats
rpm -Va
debsums
apt-get clean
apt-get autoclean
apt-file purge
*.rpm
*.deb
/etc/yum.conf
/etc/apt/sources.list
Some of the information in this table was derived (with permission) from APT and RPM Packager Lookup Tables.
More technical information about Debian-style packaging can be found in Basics of the Debian package management system and the Debian
New Maintainers' Guide.
Services
Services on Ubuntu are managed in a broadly similar way to those on Red Hat.
Graphical Tools
Services can be configured by clicking System -> Administration -> Services. A tool called Boot-Up Manager is also available.
Command Line Tools
Below is a table of example commands for managing services. The apache/httpd service is used as an example.
Task
Ubuntu
Ubuntu
(with sysv-rc-conf or sysvconfig)
chkconfig httpd on
sysv-rc-conf apache on
into runlevel 3
into runlevel 2
Note: The service and invoke-rc.d commands call init scripts to do the actual work. Also start/stop services by e.g.
Ubuntu: /etc/init.d/apache start
Red Hat/Fedora: /etc/init.d/httpd start
A.
tar.gz also known as tarball, is an archive format for electronic data and software. Most Linux tarball contains a source code for
software. If you are new to Linux I recommend using apt-get, rpm and yum command to install all binary packages. Tarballs contain
group of files in one file. Tarball files have extensions- .tar.gz, .tgz or .tar.bz2. Most open source software use tarballs to distribute
programs/source codes.
1: Uncompress tarball
To uncompress them, execute the following command(s) depending on the extension:
$ tar zxf file.tar.gz
$ tar zxf file.tgz
$ tar jxf file.tar.bz2
$ tar jxf file.tbz2
Now change directory
$ ls
$ cd path-to-software/
./configure configures the software for your system to have functionality/libraries necessary to compile the
package
make compiles all the source files into executable binaries
make install installs the binaries/supporting files into the appropriate locations
Since Kali Linux is based on Debian you cannot install RPM packages directly using apt or dpkg package managers. However, you can try a
utility called Alien which can convert one package format into other but this doesn't mean every RPM will work since packages link to another
packages for dependencies and this can cause troubles. To install Alien and necessary package, run this command
$ sudo apt-get install alien dpkg-dev debhelper build-essential
To convert a package from RPM to debian format, use this command:
$ sudo alien packagename.rpm
To install the package:
$ sudo dpkg -i packagename.deb
For standard-install routines for rpm and tar.gz files find out what the switches mean by executing the following
from the command line (CLI):
man rpm
rpm --help
man tar
tar help
Install a RPM package
rpm ivh packagename.rpm
Upgrade a RPM package
rpm Uvh packagename.rpm
Verify a RPM package was installed
1. rpm -qa | grep packagename
2. locate packagename
Create a tar file
tar cvf myfiles.tar mydir/
Debian / Ubuntu
On Debian/Ubuntu systems, useradd is a command itself, and you can create users and define options to them using this command, and adduser
is a perl script that uses useradd to create the account, asking for password, full-name, phone etc.
uname a
lsb_release a
Add user to sudo group (allows user to install software, print, use privileged mode etc.)
usermod -a -G sudo user1
(Note: chsh mean change login shell, -s is the specific shell you want for the user, in this case /bin/bash)
Logout and login back as our new Standard Non-root user (user1)
Login as new user
I am part of user1 group (my primary) and sudo group. That means I can run privileged commands or just become root if required.
Become root!
sudo su
The prompt is now root@kali not user1@kali. Root get to run anything Kali offers.
(Note: dont kill root or system processes unless you know what youre doing)
Just to confirm everything for user1 was deleted list files in home directory
ls /home
Nothing.. thats good news, all files and folders were deleted for user1.
Want to double-check?
su user1
user or update default new user information. The usermod command modifies a user account and it is useful to add
user to existing groups. There are two types of groups under Linux operating systems:
1. Primary user group.
2. Secondary or supplementary user group.
All user account related information is stored in the following files:
1.
2.
summary
Purpose
Add the user to the supplementary group(s). Use only with the -G option.
Use this GROUP as the default group.
Add the user to GRP1,GRP2 secondary group.
If you add or delete user to existing group, you must change the owner of any crontab files or at jobs manually. You must make any changes
involving NIS on the NIS server too.
A note about GUI tool
You will probably find the use of the GUI tool easy. KDE user can use KUser tool and the GNOME user can use users-admin tool called systemconfig-users:
# system-config-users
Sample outputs: