Σημαντικές εντολές σεναρίου Shell που χρησιμοποιούνται συχνά

Here is a list of some important shell commands:

—- Using Screen command
screen -ls — for a list of avaliable active screens
screen -x …. – the Name from -ls output to join to this active screen
Go out of the Screen with ‘ctrl a+d’ without stopping it

—- Harddisk and folder size
df -h – filesystemsize
du -sh * – shows the size of every folder

—- Who
whoami – list current user in current window
who – list all users logged onto the Workstation

—- Copy file to other Computer
scp filename username@ip-address:/filepath
filename is the file to copy and the rest is the Informationen for the remote Computer. You will be asked for a Password of the remote user.

—- Show Users List
cat /etc/passwd | cut -d: -f1

—- System information commands
dmesg – (for “diagnostic message”) is a command on Unix-like operating systems that prints the message buffer of the kernel. This buffer contains a variety of important messages from those printed during boot to those used for debugging software.
lspci -tv – Shows bridjes and main board
lshw – Information about installed devices
/usr/sbin/prtconf -v | more – Shows the RAM in Unix System

—- Show Linux version
uname -r
cat /proc/version

—- kill commands
kill -15 pid — is graceful Kill
kill -9 pid — is forcible Kill

—- Shows which files are open from the process
pfiles processid

—- Find a file per name
find /as -name *stat

—- Debug script
sh -x script

—- Vi commands
esc – in command mode
a – append
i – insert
q – quit
w – write
x – backspace
d – delete

shift g – springt am last line of text
:^g – list current line number
:set number – show line numbers

Cut/Paste Commands:

x – delete one character (destructive backspace)
dw – delete the current word (Note: ndw deletes n numbered words)
dd – delete the current line (Note: ndd deletes n numbered lines)
D – delete all content to the right of the cursor
d$ – same as above
:u – undo last command

Searching and Substitution commands:

/ [string] – search forward for string
? [string] – search backwards for string

Entering the Insert Mode:

i – Begin inserting text at current cursor location
I – Begin inserting text at the beginning of the current line
a – Begin appending text, one character to the right of current cursor location
shift a – Begin appending text at the end of the current line
o/O – Begin entering text one line below\above current line
ESC – Exit insertion mode and return to command mode

—- Less commands
g – go in the begining
shift g – go ende
shift 7 – Search
shift ß – Search backwards
n – go to next search match
shift n – go to before search match

—- find command
find . -name “*Sync*” -exec grep -l “501000093347053” {} \;
– finds in the current Folder all files with Name Sync, who have the string XXXX in it

—- Move files with script
ls junk* | awk ‘{print “mv “$0″ ../iraf/”$0″.dat”}’ | csh

—- Using Nohup with sqlplus
nohup sqlplus username/password @/home/sdmtest/..sql name & — the Output is in nohup.out

— remove all empty lines from a file
egrep -v ‘^$’ nohup.out > newfile.txt

—- tr command
tr [-c] [-d] [-s] [string1] [string2] output_file.txt
-c Complement the set of characters specified by string1.
-d Delete all occurrences of input characters that are specified by string1.
-s Replace instances of repeated characters with a single character.
string1 First string or character to be changed.
string2 Second string or character to change the string1.

tr -d ‘\t’ newfile — delete all Tabs from a File

—- ls commands
ls -lrt — Shows sorted file output

— show Variables value
echo $variable Name – Shows the variable
set – list of all set Variabels

—- Archivieren
tar -cf – file.dat | gzip -c > blabla.tgz — file.dat will be archived in blabla.tgz
tar -cf – * | gzip -c > blabla.tgz — all files from the Folder will be added to archive

– Shows whats in Archive without unzip
gunzip -c blsbvs.tgz | tar tvf –

– unzip only some files from archive
gunzip -c datejname | tar -xf – dateinamen mit pfad

– better compression
cat file1 file2 | gzip > foo.gz

– list the contents of a tar.gz file
tar -ztvf file.tar.gz
# t: List the contents of an archive
# v: Verbosely list files processed (display detailed information)
# z: Filter the archive through gzip so that we can open compressed (decompress) .gz tar file

—- delete recursively a folder with all elements in it
rm -r foldername

— change owner
ls -l – see user – group
chown user:group filename

— change file access rights
chmod u=rwx, g=rwx filename
chmod 777 filename

—- Examples for regular expressions:

# smug {search files for lines with ‘smug’}
# ‘^smug’ {‘smug’ at the start of a line}
# ‘smug$’ {‘smug’ at the end of a line}
# ‘^smug$’ {lines containing only ‘smug’}
# ‘\^s’ {lines starting with ‘^s’, “\” escapes the ^}
# ‘[Ss]mug’ {search for ‘Smug’ or ‘smug’}
# ‘B[oO][bB]’ {search for BOB, Bob, BOb or BoB }
# ‘^$’ {search for blank lines}
# ‘[0-9][0-9]’ {search for pairs of numeric digits}
# ‘[a-zA-Z]’ {any line with at least one letter}
# ‘[^a-zA-Z0-9] {anything not a letter or number}
# ‘[0-9]\{3\}-[0-9]\{4\}’ {999-9999, like phone numbers}
# ‘^.$’ {lines with exactly one character}
# ‘”smug”‘ {‘smug’ within double quotes}
# ‘”*smug”*’ {‘smug’, with or without quotes}
# ‘^\.’ {any line that starts with a Period “.”}
# ‘^\.[a-z][a-z]’ {line start with “.” and 2 lc letters}

—- Unix Commands list
http://www.computerhope.com/unix.htm

One response to “Σημαντικές εντολές σεναρίου Shell που χρησιμοποιούνται συχνά”

  1. Good way of describing, and nice post to take data regarding my presentation subject matter, which
    i am going to convey in academy.

Αφήστε μια απάντηση

Ανακαλύψτε περισσότερα από το Blog Velislav Krastev

Εγγραφείτε τώρα για να συνεχίσετε να διαβάζετε και να αποκτήσετε πρόσβαση στο πλήρες αρχείο.

Συνεχίστε την ανάγνωση