Corey Ganser > Technology > Linux Notes > Intro to the Linux Operating System

Intro to the Linux Operating System

Here I keep my notes for reminders of shortcuts for commands that I use frequently in Linux along with explanation of terminology.  This assumes you are using Linux command line and favors Debian distros with a biased towards running linux within a virtual machine.

  

An awesome book to reference if you are starting out is the Linux Phrasebook.  You can read it online here: http://books.google.com/books?id=3w4sjblXbjwC&printsec=frontcover&output=html

  

Logging into Linux command line, note that the password prompt will not show the password character being typed as a security measure.

  

Once logged in use the following commands to navigate the OS:

Hitting the Tab key when a file path is partially complete will auto complete the file path or command for you.  It will sound with a errror if there are more than one files that start that way, if you hit Tab twice it will show all of the files that match it within that dir. 

  


Commands

 Command What it does  Example  Notes 
 cd changes the directory  cd /var/www 
cd ..
jumps up one directory
 cd ..

 ls lists files/sub dirs in the directory that you are in   ls /var/www

ls -l
lists all of the info about the files
ls -l /var

ls -h
list all files and converts the file size into KB, MB etc as opposed to bytes
ls -h

 ls -al
shows information about the files including: owner, permissions, last modified  ls -al /var/www 
ls -R
Shows recursively all of the files/subdirectories under a dir

ls -R ~/backup

This will breakdown the contents of the backup folder and display also any sub dirs with their files

ls -m

Lists files/dirs in a comma separated list

ls -m ~/


ls -a
shows all of the files - even hidden files
ls -a ~/

ls -F
shows full names of files in the list
ls -F ~/

pwd
gives current location in the filesystem
pwd

 nano nano is a text editor for editing files in Linux  nano /var/www/test.txt  vi is another text editor that you can use.  To use vi supplemnet nano with vi 
  chown
changes the owner of a file or directory  chown bob /var/www 
rmmod pcspkr removes beeping noise from the computer if you make an error

Came in handy for me when I had to edit in the console of a virtual machine
  CTRL C
exits out of what you are doing 
When you want to exit a program or script that is running too long 
  ifconfig gets network settings for your computer  ifconfig  shows IP address, handy for VMs. 
  chmod change the permissions for a directory/file  chmod 775 /etc/program/*  permissions are beneficial for locking down files and directories 
adduser username
this adds another user to the operating system
adduser corey

passwd
allows you to change your password
passwd
this will change the password for the user you are logged in as
visudo
this opens the editor for the sudo(super user) privledges

If you add a new user that you want to have admin privledges, then you'll want to us this command
gzip
compresses a file
gzip file.sql
Handy when backing up large file(s)
gzip -d
uncompresses a zipped folder
gzip -d file.gz
note that this will only uncompress files with the gz extension
cp
copies a file/directory to a diff directory

cp web/* /var/www/

note that you put cp which copies, then the directory or file you want to copy and a space then the dir that you want to move it to
*
Wildcard
rm libby1*.jpg libby10.jpg through libby12.jpg, as well as libby1.txt
[ ]
Wildcard
rm libby1[12].jpg libby11.jpg and libby12.jpg, but not libby10.jpg
?
Wildcard
rm libby1?.jpg libby10.jpg through libby12.jpg, but not libby1.txt
scp
Another file transfer option
scp file1.txt root@www.site.com:somedir
make sure you have login access to the server you are transferring it to
mkdir
makes a new directory
mkdir test

mkdir -p
allows you to make subdirs in a new directory
mkdir -p test/test1/test2
test1 will be a subdir of test.  test2 will be a subdir of test1
mkdir -v
shows the actions of the mkdir command


mv
Move
mv /var/test/test.txt /var/www/

you can rename the file/dir by specifying the name in the path that you are moving it to
man -k
list commands that contain a word
man -k list
this helps if you know what you want to do but don't know what the command is
 --help
any command you can append --help to it to find out how to use it and its variables
ls --help

locate
this will help find files in the system
locate test
if it cannot find it try running updatedb then try it again
;
you can run multiple commands at once with a ; in between them
cd /etc/ ; cp test.txt /etc/test
This is helpful when you want to run a lot of commands at once
&&
putting && between commands will confirm that each command was succesfull before moving onto the next command
cd /etc/ && cp test.txt /etc/test This is helpful when a series of commands is performed, but if one fails causes a lot of issues

$()

allows you to substitute a command output

$ date "+%Y-%m-%d"
2005-11-24
$ mkdir $(date "+%Y-%m-%d")


cat
shows the contents of a file without having to open it in an editor
cat test.txt
cat's main purpous is to concatonate, which mean join together..helpful when you want to mash together two or more files
dog
similar to cat, but can pull content off the web
dog http://www.google.com
|
the "pipe" can submit the output of one command into the input of another command

ls -1 | less

the command shown will take the output of the list command and apply it to the less command which will decrease the amount of results
>
take the output of a command and puts it into a file
ls -l >thislist.txt
if thislist.txt doesn't exist it will be created, if it does it will be overwritten
>>
same as > but appends the previous information so that it won't overwrite the file
ls -l >>thislist.txt

less
shows one page at a time for large files
less encyclopedia.txt
Table 5.1. Key Commands for less
Key Command Action
PageDn, e, or spacebar Forward one page
PageUp or b Back one page
Return, e, j, or down arrow Forward one line
y, k, or up arrow Back one line
G or p Forward to end of file
1G Back to beginning of file
Esc-), or right arrow Scroll right
Esc-(, or left arrow Scroll left
Q Quit less

  

head
gives the first 10 lines of a file
head test.txt
you can see the first 10 lines of multiple files by seperating the files by spaces
tail
see the last 10 lines of a file
tail test.txt

tail -f
shows the last 10 lines as it updates
tail -f test.txt
helpful if you are looking at log files as if you just run tail you will keep having to run it
grep
allows you to search for text inside of files/dirs







Intermission - Helps me for editing the sections


  unzip -t


  this tests a zipped folder to confirm it hasn't been corrupted
unzip -t test.zip
  tar -zxvf -z means to zip
-x means to extract
-v verbose
-f create a file
-c create



































  

Tag page
You must login to post a comment.