0% found this document useful (0 votes)
168 views

Common Linux Commands

This document summarizes common Linux commands across several categories: 1) It outlines commands for rebooting, shutting down, switching users, and logging in/out of the system. 2) It provides an overview of commands for navigating and manipulating files and directories, including listing, copying, renaming, removing, and changing permissions of files. 3) It briefly describes commands for viewing system information, dates and times, managing processes and jobs, and getting help.

Uploaded by

abajurflorido
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views

Common Linux Commands

This document summarizes common Linux commands across several categories: 1) It outlines commands for rebooting, shutting down, switching users, and logging in/out of the system. 2) It provides an overview of commands for navigating and manipulating files and directories, including listing, copying, renaming, removing, and changing permissions of files. 3) It briefly describes commands for viewing system information, dates and times, managing processes and jobs, and getting help.

Uploaded by

abajurflorido
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Common Linux Commands

The Linux Shell Rebooting, Shutting Down the System Operators


Shell Prompt: Shutdown the system: To issue more than one command at a time:
# = user root shutdown -h now <cmd1>;<cmd2>;<cmd3>;etc.<enter>
$ = normal user Reboot the system: To pipe output from one command to another:
Common Shells: shutdown -r now <cmd>|<cmd receiving output>
bash = Bash Login as another user (in the middle of a session):
sh = Bourne su -l <username> * = matches any number of characters
csh =C To logout: ? = matches any single character
Determining your Shell: logout [] = matches on any single character found within the brackets
echo $SHELL exit [-] = matches on any single character that is within the range in the brackets
How many shells are open? [Ctrl]D \! = is equal to not
ps Enter single-user mode: > = output redirector
Opening another shell: telinit 1 >> = append output redirector
Type in csh, sh or bash < = input redirector
To close a shell: <command/program>& = run command/program in background
Type exit or press [Ctrl]D

Help / Man Commands


Log Files, special directories, etc. To see help on any command:
Startup messages = /var/log/messages man <cmd>
GRUB settings = /etc/grub.conf To get a one-line description of a command:
LILO settings = /etc/lilo.conf.anaconda man -f <cmd>
Default shell settings = /etc/passwd To see commands with a phrase in their one-line description:
Config Script: .bash_profile (runs only when you login) man –k <phrase>
.bashrc (another script file that’s run from the .bash_profile script) Generic help for almost all Linux commands:
.bash_logout (run when you logout) <cmd> -help
vi Settings: .exrc (in the user’s home directory) Standard location for HOWTO documents:
/usr/share/doc

Date / Time Commands Misc. Commands


Display a calendar: Clear the screen: Virtual Terminals
cal –m –j –y [month] [year] clear Switching between virtual terminals:
Display the date: [Alt]F1, [Alt]F2, etc.
date To get system info and the system name: [Ctrl][right-arrow] AND [Ctrl][left-arrow]
Display the date (UTC): uname -a Display device name or filename for terminal:
date –u tty

File System Commands Permissions


Low-level format a disk: To mount a filesystem: r = read (# = 4)
fdformat mount w = write (# = 2)
Set device type & size: To unmount a filesystem: x = execute (# = 1)
setfdprm umount
To format a disk: To eject a CD-ROM: Modify permissions:
mkfs eject /dev/cdrom chmod [ugo] [+-] [rwx] <file> OR
File which specifies which filesystems are chmod <number> <file>
automatically mounted at boot-up: u = user (1st #), g = group (2nd #), o = other (3rd #), none = everyone
/etc/fstab + = add, - = remove
To check the filesystem:
fsck Modify default permissions:
umask <number> (specifies which settings to clear from the def settings – effective until system
restart)
Common Linux Commands
Searching & Manipulating Files
Directory Administration To find a file:
List contents of a directory: whereis (locate a binary or man page file)OR locate (all file types)
ls [directory] find <search locations> <search criteria> <action>
-l = long directory listing where <action> can be
-la = long w/regular & hidden files (files starting with a period) -name = filename
Print working directory (current dir): -type = file (f), directory (d)
pwd -user = user name
Change directory: -group = group name
cd <pathname> -print = print to screen
To create a directory: -exec = execute a command
mkdir <dirpath> -ok = execute a command interactively
To copy a directory: -atime<arg> = find files accessed within a certain time period
cp [options] <source> <destination> where <arg> can be
-r = recursive (copy all contents of directory) exact number of days ago, +<num> = more than # days, -<num>
-i = interactive = within # days
Rename / move directory: -mtime<arg> = find files modified within a certain time period (same as atime args).
mv [options] <source> <destination> Find <search locations> <search criteria> -exec <command> {<params>} \; = execute a
-i = interactive command after finding a file.
To remove a directory:
rmdir OR rm -r <directory> Another way to find files:
Home directory shortcut: locate
cd ~ OR cd $HOME OR cd To build locate’s database:
slocate
Sorting file contents:
sort <filename>
-n = sorts numerically (instead of by text value)
Removing adjacent duplicate lines from a file:
uniq
File Administration Send to file:
To view contents of a file: tee <filename> (puts input into file – use with pipe)
cat <filename>
To view the first 10 lines of a file:
head <filename> Jobs Processes
To view the last 10 lines of a file: Job Table = specific to each shell Process Table = system-wide
tail <filename> To view background jobs: To view the process table:
To view a file screen by screen: jobs ps
less <filename> (type b to move backward through the file) To kill (stop) a background job: To kill a process:
more <filename> (only moves forward) kill %<job #> kill <process #>
To see the file type: To suspend a background job: To unconditionally terminate a process:
file <filename> bring to foreground, press [Ctrl]Z kill -9 <process #>
To concatenate multiple files into one file: To restart a background job:
cat <in file1> <in file2> > <output file> bg %<job #> Delayed Job = run at some time after you
To see the # of words, lines, etc. in a file: To bring a job to the foreground: issue the cmd
wc <filename> fg %<job #> Detached Job = run after you logout
To copy a file: To move a job from foreground to
cp [options] <source> <destination> background: To start a delayed job/process:
-r = recursive (copy all contents of directory) suspend the job, then place it in the sleep <# secs> <cmd>
-i = interactive background To start a detached job (best run in
Rename / move file: To suspend a foreground job: background):
mv [options] <source> <destination> [Ctrl]Z nohub <cmd> &
-i = interactive To kill (terminate) a foreground job:
[Ctrl]C
Common Linux Commands
User Administration Variables
To add another user: To see exported variables:
adduser env
useradd See local variables:
userconf set
To delete a user: To set a local variable:
userdel set <var name>=<value>
To delete a user and the user’s home directory and contents: if value contains spaces or metachars, place <value> between single quotes (‘)
userdel -r if you have variables that you’d like expanded inside of the <value>, use double
User accounts (uids, username, etc.) are stored in: quotes (“) and any variables listed will have their value (expanded)
/etc/passwd To export local variables:
User account passwords stored in: export
/etc/shadow To view the contents of a variable:
To change your password: echo $<var name>
passwd To remove a variable:
To change the password of another user: unset <var name>
passwd <username>
To set a standard environment for all users when they’re created:
/etc/skel directory contains files that will be placed into the user’s home directory. Aliases
To convert cleartext passwords to shadow passwords: To define an alias:
pwconv alias <alias name>=<value>
To convert passwords from shadow to cleartext passwords: if options are to be used within value, use single quotes (‘)
pwunconv To have aliases defined each time you login:
To verify the password file integrity: define them in the .bashrc file
pwck To make aliases permanent in all shells:
use the ENV variable in the .bash_profile file, define ENV=<file containing alias commands>
To remove an alias:
\<alias name> OR unalias <alias name>
Monitoring System Access (user logins)
Display who’s you’re logged in as:
who am I Functions
whoami To define a function:
Display who’s logged into the system: <function name>() { <command list>; }
who To accept command-line arguments:
Display user ID and group ID: $*
id <username> To define functions for future shells:
Display user information: define them in the set area in the .bashrc file.
finger <username>
To see detailed user login info:
finger
Display how many users are logged in: Shell Scripts
who -q ./ = look in current directory instead of /bin for script

User Group Administration M Commands


Groups are stored in: mattrib mtype
/etc/groups mdel mcopy
Verify integrity of groups file: mlabel mformat
grpck mren mrd
Change group ownership of files/directories: mdeltree mmove
chgrp mcd mmount (mount dos disk)
to include all files under a directory, use -R mdir mdu (see disk usage)
mmd mshowfat (show file’s FAT entries)
Common Linux Commands
vi Editor Compressed Files – tar, compress, gzip & RPM
Modes: Using tar (.tar):
i = insert (to left of cursor) To create a tar file:
a = append (to right of cursor) tar –cf <dest> <src>
I = insert (at beg of line) To append data to a tar file:
A = append (at end of line) tar –r <dest> <src>
[esc] = leave input mode and return to command mode To list contents of tar file:
[Insert] = toggle between insert and overwrite mode tar –tvf <tar filename>
To restore (expand) a tar file:
:w <filename> = write (save) to file tar –xvf <tar file>
u = undo change To restore (expand) a part of a tar file:
:q = quit tar –xvf <tar file> <path>/<dest>
:q! = quit without saving changes To see if tar file is readable:
:wq = write, then quit tar –tvf <tar filename>
^ = move to beg of line Using cpio:
$ = move to end of line Copy-out (create archive) mode:
:1 = move to 1st line in file <source> | cpio –cBv > <archive filename>
:$ = move to last line in file Copy-in (extract from archive) mode:
:<#> = move to line # specified cpio –icdv < <archive filename>
o = open new line below current line Using compress (.Z files):
O = open new line above current line To compress:
r = replace single char compress
R = replaces characters until you press [esc] To see percentage of space (compressed):
cw OR ce = deletes portion of word from cursor to end of word and puts you in insert use -v option
cb = deletes portion of word from cursor to beg of word To see the contents of the archive:
c$ OR U = deletes rest of line zcat <archive>
x = deletes one char To uncompress (expand):
yy = copies current line to buffer uncompress
dd = copies current line to buffer then deletes it Using gzip (.gz files):
p = inserts copied line into file below the cursor is on To compress files:
P = inserts copied line into file above the cursor is on gzip
:set number = turn on line numbers To uncompress files:
:set nonumber = turn off line numbers gunzip
/<pattern> = search for <pattern> in file To view files in archive:
n = move to next occurrence of search within file zcat
. = repeat last command RPM files & distributions:
:s/<pattern1>/<pattern2> = substitute (replace) pattern1 with pattern2 To view all RPMs installed:
:<line #1>,<line #2>s/<pattern1>/<pattern2> = sub pattern1 w/pattern2 between line #1 & line #2 rpm -qa
:1,$s<pattern1>/<pattern2> = global sub To query a single installed package:
add /c at the end of any of the sub commands to choose to replace or not rpm -q <package name>
To see detailed info on a package:
RPM Sources & Support Info rpm -qi <package name>
RPM Sources: To search for a specific installed package:
rpmfind.net/linux/RPM rpm -qa | grep <package name>
rpm.redhat.com To get a detailed list of a package that’s not installed (just the RPM file):
rpm -qip <rpm file>
Support, errata, etc.: To get a list of files for a package that’s not installed:
www.redhat.com/support/errata/index.html rpm -qlp <rpm file>
To remove a RPM installation:
rpm -e <package name>
Email To verify an installed package:
Popular email client: rpm -V <package name>
pine (uses pico editor) To freshen a package:
Another popular email client: rpm -Fvh <packagename>
mail (Elm email client)
To compose a new email:
mail <user / email>
When done editing the content, press [Ctrl]D

You might also like