Notes from
Fedora Linux Toolbox: 1000+ Commands for Fedora, CentOS, & Red Hat Power Users

Christopher Negus 978-0470082911

last modification: 9/8/15
http://www.amazon.com/Fedora-Linux-Toolbox-Commands-CentOS/dp/0470082917/ref=sr_1_cc_1?ie=UTF8&qid=1283381024&sr=1-1-catcorr

Ch1: Starting with Fedora Linux

About:

Fedora (http://fedoraproject.org)

CentOS (www.centos.org)

Yellow Dog Linux (www.yellowdoglinux.com)

Backtrack http://www.backtrack-linux.org/

DistroWatch (http://distrowatch.com/dwres.php?resource=independence).

Linux Timeline: http://files.cyberciti.biz/uploads/tips/2007/06/44218-linuxdistrotimeline-7.2.png

Comparing

Fedora is the rapid-development, cutting edge Linux system

Novell Suse same basic dual-distribution

Debian a high-quality Linux distribution

Many derivative Linux distributions-- Ubuntu Linux, KNOPPIX live CD based on Debian.

Why command line?

GUIs are meant to be easy & intuitive

Almost any time something goes wrong

Remote systems administration

Features not supported by GUI

GUI is broken or not installed


Finding Commands

bash: anycommand: command not found

why?:

You mistyped the command name.

anycommand is not in your PATH.

Might need to be the root user for the command to be in your PATH.

anycommand not installed on your computer.


Command and Sample Output Description

type mount Show the first mount command in PATH.

whereis mount Show binary, source, and man pages for mount.

locate bash.ps Find bash.ps anywhere in the file system.

which umount Find the umount command anywhere in your PATH or aliases.

rpm -qal |grep umount Find umount in any installed package.

yum whatprovides bzfs find out which package provides some feature or file

yum search somefise find any packages matching in the description, summary & package fields

Command Reference Info

-h or –help

ls --help | less

apropos crontab

whatis cat

man find

info ls

Other Notes

Installing Kali version 1.0.4 (Backtrack 6 ish)

I had display resolution problems after I did all of this, so it is a work in progress J

1. Download the correct iso from here: http://www.kali.org/downloads/

2. Open vmware (fusion or workstation)

3. Install kali from iso

I left most stuff at the default install setting except I bumped RAM to 1024

Before you do anything else copy the vmware file to a backup if possible.

4. Log in as root

5. Open terminal

6. apt-get update --fix-missing

7. apt-get install kde-plasma-desktop (from here)

I deviated from the video and set the display manager to kdm

Other instructions can be found here

8. apt-get install yakuake

Up to here it seems to work

9. apt-get install open-vm-tools (from here)

Ended up with 9GB used out of the 20GB I allocated to it

Ch2: Installing and Adding software

USB flash:
Get diskboot.img from one of the online mirrors then execute:
dd if=/media/cdrom/diskboot.img of=/dev/sda

Choosing how install proceeds:

boot: linux text

Other boot options (p17 -- 10%):

Boot Prompt HOWTO (www.tldp.org/HOWTO/BootPrompt-HOWTO.html)

nodmraid

norobe

selinux=0

Installation screens (p18 -- 11%)

Test media, Language, Keyboard, Install or upgrade, Disk partitions, boot loader, network, time zone, root password, software packages, reboot

yum:

repos (p21 -- 12%)

yum list

yum info wordpress

yum search mp3

yum whatprovides ogg123

yum install wordpress

yum groupinstall XFCE

yum update

yum

yum --disablerepo=livna search yum-utils

yum --enablerepo=livna install mplayer

yum –exclude=somepackage update

http://www.xades.com/proj/fedora_repos.html

rpm: (14%)

rpm -ivh some.rpm

rpm -Uvh some.rpm

rpm -e badpackage

rpm -q or -qa or -ql somepackage or rpm -qa | grep ogg

rpm -qi somepackage or -ql somepackage or -qlp some.rpm

Ch 3: Using the shell

Setup:

To get use of the function keys in your virtual machine on a Macbook: in the virtual machine’s settings under keyboard & mouse set Mac Profile

Basic use:

gnome-terminal -x alsamixer Start terminal with alsamixer displayed

xterm

konsole

yakuake

Virtual Terminals

Ctrl-Alt-F1 to F6

ps ps a ps au ps ax ps aw

/etc/inittab & upstart

bash history

history

history 5

!! (rum previous command)

Ctrl-r to search for string in history

Command line completion

tracer<Tab> Command completion: Completes to traceroute command

cd /home/ch<Tab> File completion: Completes to /home/chris directory

cd ~jo<Tab> User homedir completion: Completes to /home/john

echo $PA<Tab> Env variable completion: Completes to $PATH

Redirecting stdin, stdout, stderr

ls /tmp /tmpp

ls /tmp /tmmp > output.txt

ls /tmp /tmmp 2> errors.txt

ls /tmp /tmmp 2> errors.txt > output.txt

ls /tmp > output.txt

ls /tmp 2> /dev/null

mail chris < /etc/hosts

ls /tmp | sort

ls /tmp/ /tmmp 2> /dev/null | sort

rpm -qa | grep -i sql | wc -l

Using backticks, you can execute one section of a command line first and feed the output of that

command to the rest of the command line. Here are examples:

rpm -qf `which ps`

ls -l `which traceroute`

Misc

pwd, whoami

Using alias

~/.bashrc or /etc/bashrc

alias ll="ls -lh"

alias la="ls -lah"

alias cl="cd /var/log"

alias ct=”cd /usr/local/tomcat”

Others

.bashrc

watch cat /proc/loadavg

su

su bob

sudo & /etc/sudoers (root ALL=(ALL) ALL)

Environment variables

export PS1='\e[1A\e[s\e[H\e[37;41;1m\e[K \e[1C\u@\h \e[5C \w \e[5C \d \e[5C [\A] \e[0m\e[u\n--> '

PS1, PS2, PS3, PS4

set & env

export ABC=123

export PATH=$PATH:/home/fcaen

NEVER NEVER put . In your path

Simple shell scripts

debugging http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_03.html

java scripts

DailyQuote (~/java & ~/Dropbox/Ike/4361/Examples

/etc/crontab

/etc/cron.daily/newquote

myscript.sh

chmod u+x myscript.sh also talk about file permissions (table 4.1 22% loc 830)

#!/bin/bash

MYSTRING=abc

if [ $MYSTRING = abc ] ; then

echo “The variable is abc”

fi

To negate the condition

MYSTRING=abcd

if [ $MYSTRING != abc ] ; then

echo “The variable is not abc”

fi

Examples testing for numbers

MYNUMBER=1

if [ $MYNUMBER -eq 1 ] ; then echo “MYNUMBER equals 1”; fi

if [ $MYNUMBER -lt 2 ] ; then echo “MYNUMBER less than 2”; fi

if [ $MYNUMBER -le 1 ] ; then echo “MYNUMBER less than or equal to 1”; fi

if [ $MYNUMBER -gt 0 ] ; then echo “MYNUMBER greater than 0”; fi

if [ $MYNUMBER -ge 1 ] ; then echo “MYNUMBER greater than or equal 1”; fi

Testing File names

filename=$HOME

if [ -e $filename ] ; then echo “$filename exists”; fi

if [ -f “$filename” ] ; then

echo “$filename is a regular file”

elif [ -d “$filename” ] ; then

echo “$filename is a directory”

else

echo “I have no idea what $filename is”

fi

Other file test operators (table 3.1 p46 20% loc 728)

case “$VAR” in

string1)

{ action1 };;

string2)

{ action2 };;

*)

{ default action } ;;

esac

for NUMBER in 0 1 2 3 4 5 6 7 8 9

do

echo The number is $NUMBER

done

for FILE in `/bin/ls`; do echo $FILE; done

x=1

while [ $x -le 5 ]

do

echo "Welcome $x times"

x=$(( $x + 1 ))

done

VAR=0

until [ $VAR -eq 3 ]; do echo $VAR; VAR=$[$VAR+1]; done

------

#!/bin/bash

#simple script to show command line args and if test

echo $0

echo $1

echo $2

if [ "$1" ]; then

echo string not empty

else

echo string empty

fi

Debugging

bash -x myscript.sh

Debugging on part(s) of the script

set -x # activate debugging from here

w

set +x # stop debugging from here

and yes it is wierd that it is backwards – is on + is off

The Bash Guide for Beginners http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html

& man bash

DrJohn other useful things:

yakuake

fuse rpms

encfs ~/.data ~/data

sshfs bob@jrdoffice:/home/bob/Ike /Gandalf/RemoteSites/Ike

sudo mount -t cifs '//Ariel/Easy' ~/Easy -o credentials=/Gandalf/configs/.what,uid=500,gid=500

subnet scans

sudo ping -b 10.0.1.0

sudo nmap -v 10.0.1.0/16

Ch 4: Working with Files

Everything in a Linux file system can be viewed as a file (data files, directories, devices, pipes, etc)

Regular files: (20% loc 764)

file somefilename --determine type of file

touch /home/bob/newfile.ext -- create blank file

> /home/bob/newfile.txt -- create blank file

ls -l /usr/bin/apropos

file /usr/bin/whatis

file /bin/ls

directories

mkdir

x permission must be on or users can not use directory as their current directory

umask umask -S (23% loc 852)

Symbolic & Hard Links

ln -s /path/somefile.txt /newpath/symlink.txt

symbolic link – own set of permissions, can exist on different partitions, new inode number

ln /path/file.txt /newpath/hardlink.txt

hard link – same permissions, cannot exist on different partitions, same inode number

ls -li --show all info and inode numbers

symlinks ./ -- show all symbolic links in current dir

symlinks -r ./

symlinks -rv ./

device files overview only (21% loc 800)

named pipes & sockets overview only (22% loc 807)

Permissions (Table 4.1 22% loc 830)

421421421 -- rwxrwxrwx -- usergroupother

original permssions new

chmod 0700 any rwx------

chmod 0711 any rwx—x--x

chmod go+r rwx------rwxr—r--

chmod 0777 any rwxrwxrwx

chmod a=rwx any rwxrwxrwx

chmod a+rwx any rwxrwxrwx

chmod -R 700 recursive

first 0 in all above = set-UID = 4, set-GID = 2, sticky = 1 (

set-UID will now work for shell scripts

only on ext2, ext3, ext4 file systems (24% loc 900)

lsattr, chattr --- a (append only), c (compressed), d (no dump), i (immutable), j (data journaling), s (secure deletion), t (no merging), u (undeletable), A ( no atime updates), D (synchronous directory updates), S (synchronous updates), T (top of directory hierarchy)

chattr +A somefile

good to check the attributes once in a while for security purposes

Ownership

chown bob test/

chown bob:bob

chown -R bob /

traversing file system

cd or cd ~ -- change to user home directory

cd - -- change to previous directory

cd /tmp -- change to tmp off of root

cd tmp -- change to tmp off of current dir

cd .. -- change to parent dir

Copying files

cp -a /var/www/html /backupdisk

cp -R /var/www/html /backupdisk

backup methods

dd (24% loc 879)

as root:

dd if=/dev/sdg bs=512 count=1 of=$BACKUPDIR/sdg_MBR

/sbin/fdisk /dev/hda -l > $BACKUPDIR/hda_partition_table.txt

Searching for files (25 % loc 917)

updatedb

/etc/updatedb.conf

locate & locate -i & locate -r (regluar expression)

which

find / -name e100 (25% loc 925)

Other options for files

ls -l, ls -la, ls -t, ls -i etc (26% loc 955)

alias ll="ls -lh"

alias la="ls -lah"

alias cl="cd /var/lo"

md5sum someFile.txt (26% loc 964)

sha1sum someFile.txt

sha1sum -c SHA1SUM.txt

lsof ---list open files

filelight ---diskusage

tripwire

Ch 5: Manipulating Text

Regular Expressions

a* any set of characters. a, ab, abc, aefopq

. any single character. a.c matches abc adc aqc

[ ] Matches a single character in the brackets a[bcd]e abe ace ade

[^ ] Matches a single character not in the brackets a[^bc]e aqe ade

^a a at the beginning of a line

*a$ a at the end of a line

a.c three character string starting with a and ending with c

[bcf]at bat, cat, or fat

[a-d]at aat, bat, dat ...

[A-D]at Aat ...

1[3-5]7 137, 147, 157

\tHello a tab character preceding the word Hello

\.[tT][xX][Tt] txt, Txt, TXt ...

http://en.wikipedia.org/wiki/Regular_expression

Editing text files

vi, vim (http://vimdoc.sourceforge.net), joe, emacs, pico, nano

Listing text files

cat myfile.txt

cat myfile.txt > newcopy.txt

cat myfile.txt > append.txt

cat -s myfile.txt display consecutive blank lines as one

cat -n myfile.txt show numbers on lines

cat -b myfile.txt show numbers on non blank lines

head myfile

cat myfile | head

head -n 10 myfile

ps auxw | head -10

tail myfile

tail -n 25 myfile

tail -f /var/log/httpd/access_log watch web server log continuously

more myfile.txt

less myfile.txt

/bob search for a string (bob) in a file

/ repeat search

pr quick text formatting tool

rpm -qa | sort | pr - -column=2 | less

Searching for text

grep francois myfile.txt

grep 404 /var/log/httpd/access_log

ps auwx | grep init

ps auwx | grep “\[*\]”

grep -Rn xdg /etc - directory tree with line numbers in result

Sorting output

rpm -qa | grep kernel | sort

rpm -qa | grep kernel | sort -r reverse order

ps auxw | sort -k 4,4

ps auxw | sort -k 2,2n

Replacing text with sed

cat myfile.txt | sed s/christopher/chris/

sed s/christopher/chris/ < myfile.txt > newmyfile.txt

Checking for differences between files with diff

diff /etc/named.conf.rpmnew /etc/named.conf

diff -u f1.txt f2.txt -- adds modification dates and times to output

seq 1 15 > f1.txt

sed s/4/four/ < f1.txt > f2.txt

vimdiff f1.txt f2.txt -- opens files side by side in vim

Using awk to process columns

ps auxw | awk '{print $1 $11}' --only show columns 1 & 11

ps auxw | awk '/bob/ {print $1, $11}' --show bob's processes

Converting text files to different Formats

unix2dos < f1.txt > f2.txt

dos2unix < f2.txt > f1.txt

Other

http://upstart.ubuntu.com/

http://upstart.ubuntu.com/wiki/UpstartOnFedora?highlight=((CategoryDistributions))

Book Excerpt: A Practical Guide to Fedora and Red Hat Enterprise Linux

Ch 6: Multimedia

To split avi (or other video) files: Online Documentation

ffmpeg -ss 01:09:12 -t 01:15:23 -i Family-19970512-19971225.avi ./19970702.avi

To join avi (or other video) files: Online Documentation

mencoder -ovc copy -oac copy -o 19950326-BelindaTap.avi 19950326-BelindaTap-1.avi /

19950326-BelindaTap-2.avi

To convert between types of video (Do not use on DRM files!)

transcode -y xvid -Z 720 -b 224 -i VTS_03_1.VOB -o newfile.avi

transcode -y xvid -Z 720 -b 224 -i oldfile.mpg -o newfile.avi

works ok but you loose 5.1 surround

Handbrake

Brief Audio tools

play -h

play somesong.wav

play hi.au vol .6

ogg123 mysong.ogg

ogg123 -z *.ogg --play in random order

ogg123 -Z *.ogg -- play in random order forever

ogg123 /home/bob/music -- play music in music and subdirectories

mpg321 mysong.mp3

mpg321 -@ myplaylist

alsamixer

alsamixergui

cdparanoia -vsQ -- is CD drive capable of ripping music

cdparanoia -B -- rip tracks as wav files by track name

cdparanoia -B -- “5-7” -- rip tracks 5, 6, 7 as seperate files

oggenc mysong.wav -- encodes mysong from wav to ogg

oggenc ab.flac -o ab.ogg -- encodes flac to ogg

oggenc song.wav -q 9 -- raises quality level from default of 3 to 9

oggenc song.wav -o song.ogg -a Bernstein -G Classical -d 06/05/1972 -t “Simple Song” /

-l “Album Name” -c info=”From Kennedy Center”

-- sox the Swiss army knife of audio manipulation (Online Documentation)

sox head.wav tail.wav output.wav -- concatenate two wav files

sox sound1.wav -a stat -- display information about the file