Вы находитесь на странице: 1из 4

Unix Commands - pico (.

emacs) or vi

Opening terminal and accessing help

Down to the left you find the console which is the shell program console or the
bash or terminal program and command line to the system.

List Command ls - Gives all the visibles folders and


files in the current directory
Help Command man ls - Gives documentation about the commands,
here "ls"
Help Topics Info ls - Gives more in depth information about
the command
Exit Command q - Exits from the current line command
Clear Console clear - Gives a fresh console

File System Navigation

Identify current directory pwd


Show all hidden and visible files ls -a
Shows all access levels for files ls -l
Shows all access levels for files dir
Shows the index or reference # dir -i
Change directory cd Desktop The directory is case sensitive
Takes you up one directory cd ../
Takes you up one directory cd ..
To go to the home directory cd /home/linux Hit tab for linux
to complete command

File Creations

Creating a new file touch test.txt


Running text editors pico test.txt
Opening a text editor only pico
Running another text editor vi test.txt

File Viewing

Displays file content more test.txt


Displays in text editor form less test.txt
Display first ten lines of file head test.txt Used for
previewing files
Display the last ten lines of file tail test.txt
Concatinating files cat text.txt text2.txt
Prints out the content of both files
Pipe files into one complete file cat text.txt text2.txt >> total.txt
Search for patterns in a file grep A test.text Searches for words that
have a pattern of A
Searches diferences between files diff text.txt text2.txt
Returns the type of file file text.txt Identifies file
structure as text
Search man pages apropos rpm Searches all relevant topics to
rpm in man
prints hex info of file hex dump test.txt

File manipulaton

Deleting files rm total.txt


Copying files cp test.txt total.txt Copies test.txt and renames
to total.txt
Moving files mv total.txt Desktop Moves file to the local
Desktop directory
Creating directories mkdir delete_me Creates a directory called
delete_me
Remove directory rmdir delete_me Deletes directory only if empty
Delete fulll directory cd delete_me 4 command lines - Need to be
in folder
rm *
cd ..
rmdir delete_me

Console Programming

Finding login info whoami


Prints to the console screen echo hello world
Prints the current date date
Print calendar cal
Keylogger to the screen showkey -a After hitting Enter, shows
Enter character
Exitting the console Exit
Shutting down the system halt
Rebooting the machine reboot

Writing a bash shell program Series of executions that can be done in


the command line

cd Desktop
touch shellscript
chmod 777 shellscript
pico shellscript

-----------------------------------------------------------------------------------
------------------------------------
#!/bin/bash Header saying this is a shell script

tmp=5
echo $tmp
-----------------------------------------------------------------------------------
------------------------------------

./shellscript ./ Execture in this directory this file


pico shellscript

-----------------------------------------------------------------------------------
-------------------------------------
#!/bin/bash

for i in *
do
echo $i
done
-----------------------------------------------------------------------------------
--------------------------------------
./shellscript Prints out all ls files
pico shellscript
-----------------------------------------------------------------------------------
--------------------------------------

#!/bin/bash To support floating points

piovertwo=`echo 5 k 3.14 2.0 \/ p | dc` 5 decimal places postfix and pop stack
on desktop calc
echo $piovertwo
-----------------------------------------------------------------------------------
---------------------------------------

./shellscript Returns the floating point result


pico shellscript

-----------------------------------------------------------------------------------
--------------------------------------
#!/bin/bash
threeovertwo= `expr 3/2`
echo $threeovertwo
-----------------------------------------------------------------------------------
---------------------------------------

./shellscript Returns the modulus of the division


pico shellscript

-----------------------------------------------------------------------------------
--------------------------------------
#!/bin/bash
who= `echo | whoami`
echo $who

-----------------------------------------------------------------------------------
----------------------------------------

pico shellscript
-----------------------------------------------------------------------------------
----------------------------------------
#!/bin/bash

touch testfromscript
chmod 555 testfromscript
cp testfromscript tfs2
ls -a
-----------------------------------------------------------------------------------
----------------------------------------

./shellscript Creates testfromscript which ws copied to tfs2


and lists directory
pico shellscript
-----------------------------------------------------------------------------------
-----------------------------------------
#!/bin/bash

echo Please enter a number.


read num
tt=`expr $num \* 10`
echo $tt
-----------------------------------------------------------------------------------
------------------------------------------
./shellscript Requests a number from a user and multiplies it to 10.

Вам также может понравиться