۱۳۹۲ آذر ۱۵, جمعه

دستورات لازم SSH

یک سری دستورات توی ssh هستن که معمولا زیاد ازشون استفاده میشه و بهتره که همیشه اونا رو به ذهن داشته باشیم

یا به اصطلاح برگه تقلبی از ssh از دستوراتش همیشه دم دستمون باشه

ssh cheat sheet



Delete an entire directory and all of its contents:
rm -r -f YourDirectory What’s happening: rm = remove / delete -r = recursively deletes the directory and all files in it, including subdirectories -f = will not ask for confirmation before deleting
Extract a TAR.GZ File
tar -xvf yourfilename.tar.gz What’s happening: tar – is calling the tar program -x – extract -z – it’s gzipped (so omit the z if you merely have a .tar file) -f – supplying filename on command line.
Move a directory and/or files to another location on the server:
mv directory/* html/ What’s happening: mv – move directory/* – All files/folders inside the Directory folder html/ – Location of where the files will be moved to
Note: When something is specified in brackets, such as [command] or [filename], it is used to indicate that you must input your desired information here. Do NOT include brackets in your command. Navigating in UNIX



















































pwdنمایش مسیر جاری
lsنمایش فهرستی از فایل ها و فولدر های مسیری که در آن هستیم
ls -alلیستی از فایل ها و اطلاعاتشان
ls –alRلیستی از فایل ها و اطلاعاتشان در تمام زیر فهرست ها
ls -alR | moreهمانند دستور قبلیه فقط وقتی صفحه پر شد منتظر میمونه تا شما با فشردن کلیدی ادامه رو فراخوانی کنید
ls -alR > filename.txtاین هم همون دستور قبلی رو به صورت خروجی توی یک فایل ذخیره میکنه
ls *.htmlشما میتونید فایل ها رو با هر پسوندی لیست کنید مثلا اینجا html رو خواسته
cd [directory name]تعویض مسیر یا رفتن به یک دایرکتوری دیگه
cd ..با این دستور به دایرکتوری بالاتر از مسیری که هستید بر میگردید
clearصفحه رو پاک میکنه
vdirجزئیات بیشتری از فهرست فایل ها نسبت به دستور ls نمایش میده
exitاز شل خارج میشه

Moving, Copying and Deleting Files























mv [old filename] [new filename]انتقال یا تغییر نام یک فایل
cp [filename] [new filename]کپی کردن فایل
rm [filename]حذف یک فایل
rm *این دستور تمام فایل ها و دایرکتوری های مسیر جاری رو حذف میکنه
rm *.htmlاین دستور هم فایل هایی با پسوند html رو حذف میکنه

Creating, Moving, Copying and Deleting Directories















mkdir [directory name]ایجاد یک فولدر یا دایرکتوری
ls -d */لیست تمام دایرکتوری های مسیر جاری
cp -r [directory] [new directory]کپی کردن یک دایرکتوری با تمام محتویات داخلش

Searching Files and Directories











find . -name [filename] -printجستجوی یک فایل با نام در مسیر جاری
grep [text] [filename]جستجوی یک متن داخل فایل ها

File and Directory Permissions There are three levels of file permissions: read, write and execute.  In addition, there are three groups to which you can assign permissions: file owner, user group and everyone.  The command chmod followed by three numbers is used to change permissions.  The first number is the permission for the owner, the second for the group and the third for everyone.  Here are how the levels of permission translate:



































0 = —بدون حق دسترسی
1 = –Xفقط اجرا
2 = -W-فقط نوشتن
3 = -WXنوشتن و اجرا
4 = R–فقط خواندن
5 = R-Xخواندن و اجرا
6 = RW-خواندن و نوشتن
7 = RWXخواندن نوشتن و اجرا

It is preferred that the group always have permission of 0.  This prevents other users on the server from browsing files via Telnet and FTP.  Here are the most common file permissions used:























chmod 604 [filename]حداقل حق دسترسی یک فایل html
chmod 705 [directory name]حداقل حق دسترسی یک دایرکتوری یا فولدر
chmod 755 [filename]حداقل حق دسترسی به برنامه ها و اسکریپت ها
chmod 606 [filename]حق دسترسی به فایل های داده مورد نیاز برنامه ها
chmod 703 [directory name]حق دسترسی فقط نوشتن برای public_ftp

How do I unzip a file with telnet?


All of the below commands assume that you are within the same directory that the compressed file is in. To be sure type: ls {enter} If the file is there, you’re ready to go. If not type: cd /big/dom/xdomain/www/directory/ {enter} replacing the path with the correct path to your file. If a file ends in .zip (for example, file.zip) type: unzip file.zip If a file ends in .tar (e.g., file.tar) type: tar -xvf file.tar If a file ends in .gz (for example, file.gz) type: gzip -d file.gz If a file ends in .tar.gz (e.g. file.tar.gz) type: gzip -d file.tar.gz and then tar -xvf file.tar If a file ends in .tgz (e.g. file.tgz)



















zip [options] [zipfile] [files]

The zip command compresses a file or list of files into a zip format archive file. This command is compatible with pkzip on a PC. Simply type “zip zipfile file1 file2 file3″ at a telnet command prompt and replace zipfile with the name you want to use for your compressed zip archive file, and replace fileX with the name of the file(s) you want to compress into the zip archive.



For example, type “zip backup.zip home.html index.html” at a telnet command prompt to compress and archive the files called home.html and index.html into the file called backup.zip.




























unzip [options] [zipfile]

The unzip command extracts a zip format archive file. This command is compatible with pkunzip files from a PC. Simply type “unzip zipfile” at a telnet command prompt and replace zipfile with the name of your zip format archive file.



For example, type “unzip -aL old.zip” at a telnet command prompt to extract files contained in the archive called old.zip. The “-aL” are options that are generally useful when unzipping files created on a PC.




Moving files via SSH


Often you will need to move one or more files/folders or copy them to a different location. You can do so easily using an SSH connection. The commands which you would need to use are mv (short for ‘move’) and cp (short for ‘copy’).

The mv command syntax looks like this:
mv configuration.php-dist configuration.php

By issuing the above command we will move (rename) the file configuration.php-dist to configuration.php.

You can also use mv to move a whole directory and its content:
mv includes/* ./

This will move all files (and folders) in the includes/ directory to the current working directory.

In some cases however, we will need to only update the files and move only files that were changed, which we can do by passing ‘-u’ as argument to the command:
mv -u includes/* admin/includes

The copy (cp) command works the same way as mv, but instead of moving the files/folders it copies them. For example:
cp configuration.php-dist configuration.php

The command will copy the configuration.php-dist file to configuration.php and will preserve the original file (the file will NOT be removed after it is copied).

cp also accepts various arguments:
cp -R includes/ includes_backup/

-R instructs cp to copy files recursively (for example, a whole directory). To overwrite already existing files you should use the -f argument:
cp -Rf includes/ admin/includes/

هیچ نظری موجود نیست:

ارسال یک نظر