صفر و یک - برنامه نویسی - لینوکس

دست نوشته های شخصی من در مورد نرم افزار، سیستم عامل و برنامه نویسی لینوکس

صفر و یک - برنامه نویسی - لینوکس

دست نوشته های شخصی من در مورد نرم افزار، سیستم عامل و برنامه نویسی لینوکس

لیدورا یک وبلاگ تخصصی برنامه نویسی یا لینوکس نیست. بیشتر محلیه برای ثبت چیزهایی که قراره بیشتر از یه بار خونده بشن. اگه به درد شما هم خورد که زکات دانش ما پرداخت شده، شکر.

آخرین نظرات

نویسندگان

آموزش نصب بسته‌ی cheat

دوشنبه, ۳۱ شهریور ۱۳۹۳، ۰۱:۰۵ ب.ظ

Trminal Commands

 

چند روز پیش اینجا مطلبی در مورد دستور cheat دیدم که خیلی ازش خوشم اومد. cheat یه دستور خط فرمانه که اطلاعاتی راجع به بسته‌های خط فرمان در اختیار کاربر می‌گذاره. راه معمولی کمک گرفتن در مورد بسته‌ها اینه که از man یا سوئیچ help-- استفاده کنیم. اما بعضی وقت‌ها man بیش از حد طولانیه و help-- بیش از حد کوتاه. cheat برای دستورهای خط فرمان یه Cheat-Sheet مفید تهیه کرده که استفاده از اون راحت‌تر از استفاده از دستورات مشابهه.

مثلا برای دستور tar قسمتی از خروجی man این شکلیه:

TAR(1)                          GNU TAR Manual                          TAR(1)


NAME
       tar - an archiving utility

SYNOPSIS
   Traditional usage
       tar {A|c|d|r|t|u|x}[GnSkUWOmpsMBiajJzZhPlRvwo] [ARG...]

   UNIX-style usage
       tar -A [OPTIONS] ARCHIVE ARCHIVE

       tar -c [-f ARCHIVE] [OPTIONS] [FILE...]

       tar -d [-f ARCHIVE] [OPTIONS] [FILE...]

       tar -t [-f ARCHIVE] [OPTIONS] [MEMBER...]

       tar -r [-f ARCHIVE] [OPTIONS] [FILE...]

       tar -u [-f ARCHIVE] [OPTIONS] [FILE...]

       tar -x [-f ARCHIVE] [OPTIONS] [MEMBER...]

   GNU-style usage
       tar {--catenate|--concatenate} [OPTIONS] ARCHIVE ARCHIVE

       tar --create [--file ARCHIVE] [OPTIONS] [FILE...]

       tar {--diff|--compare} [--file ARCHIVE] [OPTIONS] [FILE...]

       tar --delete [--file ARCHIVE] [OPTIONS] [MEMBER...]

       tar --append [-f ARCHIVE] [OPTIONS] [FILE...]

       tar --list [-f ARCHIVE] [OPTIONS] [MEMBER...]

       tar --test-label [--file ARCHIVE] [OPTIONS] [LABEL...]

       tar --update [--file ARCHIVE] [OPTIONS] [FILE...]

       tar --update [-f ARCHIVE] [OPTIONS] [FILE...]

       tar {--extract|--get} [-f ARCHIVE] [OPTIONS] [MEMBER...]

NOTE
       This manpage is a short description of GNU tar.  For a detailed discus‐
       sion, including examples and usage recommendations, refer  to  the  GNU
       Tar Manual available in texinfo format.  If the info reader and the tar
       documentation are properly installed on your system, the command

 

و قسمتی از خروجی help--

Usage: tar [OPTION...] [FILE]...
GNU 'tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.

Examples:
  tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.
  tar -tvf archive.tar         # List all files in archive.tar verbosely.
  tar -xf archive.tar          # Extract all files from archive.tar.

 Main operation mode:

  -A, --catenate, --concatenate   append tar files to an archive
  -c, --create               create a new archive
  -d, --diff, --compare      find differences between archive and file system
      --delete               delete from the archive (not on mag tapes!)
  -r, --append               append files to the end of an archive
  -t, --list                 list the contents of an archive
      --test-label           test the archive volume label and exit
  -u, --update               only append files newer than copy in archive
  -x, --extract, --get       extract files from an archive

 Operation modifiers:

      --check-device         check device numbers when creating incremental
                             archives (default)
  -g, --listed-incremental=FILE   handle new GNU-format incremental backup
  -G, --incremental          handle old GNU-format incremental backup
      --ignore-failed-read   do not exit with nonzero on unreadable files
      --level=NUMBER         dump level for created listed-incremental archive
  -n, --seek                 archive is seekable
      --no-check-device      do not check device numbers when creating
                             incremental archives
      --no-seek              archive is not seekable
      --occurrence[=NUMBER]  process only the NUMBERth occurrence of each file
                             in the archive; this option is valid only in
                             conjunction with one of the subcommands --delete,
                             --diff, --extract or --list and when a list of
                             files is given either on the command line or via
                             the -T option; NUMBER defaults to 1
      --sparse-version=MAJOR[.MINOR]
                             set version of the sparse format to use (implies
                             --sparse)
  -S, --sparse               handle sparse files efficiently

 Overwrite control:

  -k, --keep-old-files       don't replace existing files when extracting,
                             treat them as errors
      --keep-directory-symlink   preserve existing symlinks to directories when
                             extracting
      --keep-newer-files     don't replace existing files that are newer than
                             their archive copies
      --no-overwrite-dir     preserve metadata of existing directories
      --one-top-level[=DIR]  create a subdirectory to avoid having loose files
                             extracted
      --overwrite            overwrite existing files when extracting
      --overwrite-dir        overwrite metadata of existing directories when
                             extracting (default)
      --recursive-unlink     empty hierarchies prior to extracting directory
      --remove-files         remove files after adding them to the archive
      --skip-old-files       don't replace existing files when extracting,
                             silently skip over them
  -U, --unlink-first         remove each file prior to extracting over it
  -W, --verify               attempt to verify the archive after writing it

 Select output stream:

      --ignore-command-error ignore exit codes of children
      --no-ignore-command-error   treat non-zero exit codes of children as
                             error
  -O, --to-stdout            extract files to standard output
      --to-command=COMMAND   pipe extracted files to another program

 Handling of file attributes:

      --atime-preserve[=METHOD]   preserve access times on dumped files, either
                             by restoring the times after reading
                             (METHOD='replace'; default) or by not setting the
                             times in the first place (METHOD='system')
      --delay-directory-restore   delay setting modification times and
                             permissions of extracted directories until the end
                             of extraction
      --group=NAME           force NAME as group for added files
      --mode=CHANGES         force (symbolic) mode CHANGES for added files
      --mtime=DATE-OR-FILE   set mtime for added files from DATE-OR-FILE
  -m, --touch                don't extract file modified time
      --no-delay-directory-restore
                             cancel the effect of --delay-directory-restore
                             option
      --no-same-owner        extract files as yourself (default for ordinary
                             users)
      --no-same-permissions  apply the user's umask when extracting permissions
                             from the archive (default for ordinary users)
      --numeric-owner        always use numbers for user/group names
      --owner=NAME           force NAME as owner for added files
  -p, --preserve-permissions, --same-permissions
                             extract information about file permissions
                             (default for superuser)
      --preserve             same as both -p and -s
      --same-owner           try extracting files with the same ownership as
                             exists in the archive (default for superuser)
  -s, --preserve-order, --same-order
                             member arguments are listed in the same order as
                             the files in the archive
      --sort=ORDER           directory sorting order: none (default), name or
                             inode

 Handling of extended file attributes:

      --acls                 Enable the POSIX ACLs support
      --no-acls              Disable the POSIX ACLs support
      --no-selinux           Disable the SELinux context support
      --no-xattrs            Disable extended attributes support
      --selinux              Enable the SELinux context support
      --xattrs               Enable extended attributes support
      --xattrs-exclude=MASK  specify the exclude pattern for xattr keys
      --xattrs-include=MASK  specify the include pattern for xattr keys

 Device selection and switching:

  -f, --file=ARCHIVE         use archive file or device ARCHIVE
      --force-local          archive file is local even if it has a colon
  -F, --info-script=NAME, --new-volume-script=NAME
                             run script at end of each tape (implies -M)
  -L, --tape-length=NUMBER   change tape after writing NUMBER x 1024 bytes
  -M, --multi-volume         create/list/extract multi-volume archive
      --rmt-command=COMMAND  use given rmt COMMAND instead of rmt
      --rsh-command=COMMAND  use remote COMMAND instead of rsh
      --volno-file=FILE      use/update the volume number in FILE

 

اما خروجی cheat خیلی واضح و خلاصه استفاده از tar رو آموزش می‌ده:

 

@aliHost:~/cheat % cheat tar 

# To extract an uncompressed archive:
tar -xvf /path/to/foo.tar

# To create an uncompressed archive:
tar -cvf /path/to/foo.tar /path/to/foo/


# To extract a .gz archive:
tar -xzvf /path/to/foo.tgz

# To create a .gz archive:
tar -czvf /path/to/foo.tgz /path/to/foo/

# To list the content of an .gz archive:
tar -ztvf /path/to/foo.tgz

# To extract a .bz2 archive:
tar -xjvf /pathali
# To create a .bz2 archive:
tar -cjvf /path/to/foo.tgz /path/to/foo/

# To list the content of an .bz2 archive:
tar -jtvf /path/to/foo.tgz

# To create a .gz archive and exclude all jpg,gif,... from the tgz
tar czvf /path/to/foo.tgz --exclude=\*.{jpg,gif,png,wmv,flv,tar.gz,zip} /path/to/foo/

 

اگه از cheat خوشتون اومد برای نصبش کارهای زیر رو انجام بدید:

 

1- نصب پیش نیاز‌ها

فدورا

# yum install git python-pip

آرچ

# pacman -S git python-pip

اوبونتو

# apt-get install git python-pip 

 

۲- دانلود و نصب cheat

# pip install docopt pygments
# git clone https://github.com/chrisallenlane/cheat.git
# cd cheat
# python setup.py install

 

اگه cheat با موفقیت نصب شده باشه دستور زیر باید ورژن cheat رو نشون بده

# cheat -v 

cheat 2.0.9

 

۳- آماده سازی cheat برای استفاده

اول یه ویرایشگر برای شل پیش‌فرض انتخاب کنید:

خط زیر رو به فایل bashrc. اضافه کنید

export EDITOR =/usr/bin/nano

*** به جای nano می‌تونید از ویرایشگر محبوب خودتون مثلا vi استفاده کنید.

*** اگه از zsh استفاده می‌کنید فایل zshrc. رو ویرایش کنید.

 

حالا باید ویژگی تکمیل خودکار رو به شل اضافه کنید:

به مسیر زیر برید:

/etc/bash_completion.d/

*** اگه مسیر bash_completion.d وجود نداشت اون رو بسازید.

 

حالا بسته به شلی که از اون استفاده می‌کنید فایل پیکره‌بندی رو اضافه کنید

bash

# wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.bash 

zsh

# wget https://github.com/chrisallenlane/cheat/raw/master/cheat/autocompletion/cheat.zsh

 

برای نمایش خروجی رنگی خط زیر رو به bashrc. یا zshrc. اضافه کنید.

export CHEATCOLORS=true

 

مسیر cheat-sheet ها رو پیدا کنید:

$ cheat -d 

/home/ali/.cheat 
/usr/lib/python3.4/site-packages/cheat/cheatsheets

و به مسیر خانگی خودتون انتقالشون بدید:

# cp /usr/lib/python3.4/site-packages/cheat/cheatsheets/* ~/.cheat

 

کار نصب به پایان رسید. این هم چند تا خروجی نمونه:

ali@aliHost:~|⇒  cheat iwconfig
# Display wireless settings of the first wireless adapter
iwconfig wlan0

# Take down / up the wireless adapter
iwconfig wlan0 txpower {on|auto|off}

# Change the mode of the wireless adapter
iwconfig wlan0 mode {managed|ad-hoc|monitor}

 

ali@aliHost:~|⇒  cheat wget
# To download a single file
wget http://path.to.the/file

# To download a file and change its name
wget http://path.to.the/file -o newname

# To download a file into a directory
wget -P path/to/directory http://path.to.the/file

# To continue an aborted downloaded
wget -c http://path.to.the/file

# To download multiples files with multiple URLs
wget URL1 URL2

# To parse a file that contains a list of URLs to fetch each one
wget -i url_list.txt

# To mirror a whole page locally
wget -pk http://path.to.the/page.html

# To mirror a whole site locally
wget -mk http://site.tl/

# To download files according to a pattern
wget http://www.myserver.com/files-{1..15}.tar.bz2

# To download all the files in a directory with a specific extension if directory indexing is enabled
wget -r -l1 -A.extension http://myserver.com/directory

# Allows you to download just the headers of responses (-S --spider) and display them on Stdout (-O -).
wget -S --spider -O - http://google.com

 

ali@aliHost:~|⇒  cheat dd
# Read from {/dev/urandom} 2*512 Bytes and put it into {/tmp/test.txt}
# Note: At the first iteration, we read 512 Bytes.
# Note: At the second iteration, we read 512 Bytes.
dd if=/dev/urandom of=/tmp/test.txt count=512 bs=2

# Watch the progress of 'dd'
dd if=/dev/zero of=/dev/null bs=4KB &; export dd_pid=`pgrep '^dd'`; while [[ -d /proc/$dd_pid ]]; do kill -USR1 $dd_pid && sleep 1 && clear; done

# Watch the progress of 'dd' with `pv` and `dialog` (apt-get install pv dialog)
(pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror) 2>&1 | dialog --gauge "Running dd command (cloning), please wait..." 10 70 0

# Watch the progress of 'dd' with `pv` and `zenity` (apt-get install pv zenity)
(pv -n /dev/zero | dd of=/dev/null bs=128M conv=notrunc,noerror) 2>&1 | zenity --title 'Running dd command (cloning), please wait...' --progress

# DD with "graphical" return
dcfldd if=/dev/zero of=/dev/null bs=500K

نظرات  (۵)

انصافانه خیلی خوب بود. خیلی کمک کرد. راستی من که خیلی مشتاقم در مورد archlinux بیشتر بدونم.
پاسخ:
ممنون سعید.
اگه سرت درد می‌کنه واسه دردسر بسم الله. واقعا عالیه. اما حتما اول ویرچوال نصبش کن. 
1. اگر مثل man صفحه بندی داشت خیلی خوب بود. یعنی با space جلو می رفتیم و با q خارج میشدیم.
در حالت فعلی بایذ scroll کنیم!
2. برای دوری از سردرد، به جای آرچ، antergos نصب کنید.  کاملا از مخازن آرچ استفاده میکنه.
پاسخ:
drofa عزیز
1. می‌تونید با اپراتور | خروجی رو به less یا more هدایت کنید.
۲. قبلا چندتا توزیع آرچ بیس مثل آرچ بنگ رو انتحان کرده بودم، خیلی کار رو راحت می‌کنن.
1. فایل cheat.bash را باید در /etc/bash_completion.d/ قرار بدیم؟
2. دستور cp آخری رو با cp -r نباید انجام بدیم؟! چون پیغام می ده یک پوشه __pycache__ هم وجود داره.
3. کارهای آخری مثل کپی کرد cheatSheetها به home برای چی بود؟

در هر حال، از من که رنگی نشد!
پاسخ:
۱. بله. اگه نداریدش بسازیدش اول
۲. حق با شماست ولی نیازی به کپی اون پوشه نیست هر چند خودم بار اول کپیش کردم :)
۳. برای اینکه کاربر فعلی بتونه از تمام دستورات cheat استفاده کنه.

ماله منم نشد :) اما باید می‌شد :

Optionally, you can also enable syntax highlighting, if desired. To active syntax highlighting feature, add a CHEATCOLORS environment variable in your ‘.bashrc‘ file.


جالب بود! ممنون!
پاسخ:
خواهش می‌کنم صابر جان.
درود
ممنون از مطلب خوبت . واقعا اگه نگیم وبلاگت بهترینه جزو بهترین های فارسی زبان هست .
امیدوارم همیشه بروز باشی و ما رو هم بی نصیب نذاری :)
دیروز هرکار کردم نشد با Abrowser توی تریسکل بهت پیام بدم یا نظر بذارم و هدایت میشدم
به صفحه ای که میگفت اجازه دسترسی ندارید نمیدونم مشکل از افزونه های منه یا خود مرورگرم .
برای رنگی شدن خطوط باید خط زیر رو از zshrc یا bashrc پاک کرد .

export EDITOR =/usr/bin/nano



پاسخ:
مرسی فرهاد عزیز. تو همیشه به من لطف داشتی.

ارسال نظر

ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی