Curl is a command line tool for transferring data to and from servers.
- Post JSON with CURL
curl -X POST https://reqbin.com/echo/post/json
-H 'Content-Type: application/json'
-d '{"login":"my_login","password":"my_password"}'- POST file with CURL
curl -X POST https://reqbin.com/echo/post/json -d @filename.ext- POST XML
curl -X POST https://reqbin.com/echo/post/xml
-H "Content-Type: application/xml"
-H "Accept: application/xml"
-d "<xml_data>....</xml_data>"- GET
json
curl https://reqbin.com/echo/get/json
-H "Accept: application/json"- GET
xml
curl https://reqbin.com/echo/get/xml
-H "Accept: application/xml"- GET
html
curl https://reqbin.com/echo
-H "Accept: text/html"- Limiting the maximum transfer rate for Curl GET requests
curl https://reqbin.com/echo
--limit-rate 50K- Sent custom HTTP headers using Curl
curl https://reqbin.com/echo/get/json
-H "X-Custom-Header: value"
-H "Content-Type: application/json"
-H "Accept: application/json"- Only get HTTP headers using Curl
curl -I https://reqbin.com/echo- Curl POST Form Syntax
curl -X POST [URL]
-H "Content-Type: application/x-www-form-urlencoded"
-d "key1=value1&key2=value2"- Curl POST Form with multipart/form-data Format
curl https://reqbin.com/echo/post/form
-F key1=value1
-F key2=value2
-F photo=@photo.pngcurl -k https://expired.badssl.comcurl --insecure https://expired.badssl.comcurl -X DELETE http://reqbin.com/echo/delete/json?id=1
-H "Accept: application/json"- Curl Proxy Syntax
curl -x "[protocol://][host][:port]" [URL] [options]- Allow Insecure SSL Connections for Curl Proxy Requests
curl -x "[protocol://][host][:port]" -k [URL]- Curl SOCKS Proxy Syntax
curl -x "[socks5://][host][:port]" [URL] [options]
curl --socks5 "[host][:port]" [URL] [options]- Specify proxy username and password
curl -x "[protocol://][host][:port]" [URL] -U login:password- CURL Client Certificate Example
curl -E cerfile.crt https://reqbin.com/echo
curl --cert cerfile.crt https://reqbin.com/echo- CURL CA Certificate Example
curl --cacert mycompany.cert https://www.mycompany.com/internalSed command in Unix OS can perform a lot of function like searching, find and replace, insertion or deletion.
-
Syntax:
sed OPTIONS... [SCRIPT] [INPUTFILE...]
-
Substituting string
sspecifies the substitution operation./are delimiters.[nth]specifies the nth occurences of a pattern in a line. (emptymeans1).gspecifies all the occurences of a pattern in a line.[line_number]specifies line number. (emptymeansall).$the last line.$ sed 's/[search_pattern]/[replacement_string]/[nth]' [file_name] $ sed 's/unix/LINUX/' geekfile.txt $ sed 's/unix/LINUX/2' geekfile.txt $ sed 's/[search_pattern]/[replacement_string]/g' [file_name] $ sed 's/unix/LINUX/g' geekfile.txt $ sed 's/[search_pattern]/[replacement_string]/[nth]g' [file_name] $ sed 's/unix/LINUX/3g' geekfile.txt $ sed '[line_number[,line_number]] s/[search_pattern]/[replacement_string]/[nth]g' [file_name] $ sed '[line_number,$] s/[search_pattern]/[replacement_string]/[nth]g' [file_name] $ sed '3 s/unix/linux/' geekfile.txt $ sed '1,3 s/unix/linux/' geekfile.txt $ sed '2,$ s/unix/linux/' geekfile.txt -
Replace with re
$ sed 's/\([re_pattern]\)/\1/[nth]g' $ echo "Welcome To The Geek Stuff" | sed 's/\(\b[A-Z]\)/\(\1\)/g' -
Duplicating the replaced line
pspecifies duplicating.nprint only the replaced lines$ sed [-n] 's/[search_pattern]/[replacement_string]/p' [file_name] $ sed 's/unix/linux/p' geekfile.txt $ sed -n 's/unix/linux/p' geekfile.txt -
Deleting lines from a particular file
dspecifies deleting.$ sed '[line_number[,line_number]]d' [file_name] $ sed '5d' filename.txt $ sed '$d' filename.txt $ sed '3,6d' filename.txt $ sed '12,$d' filename.txt $ sed '/[re_pattern]/d' [file_name] $ sed '/abc/d' filename.txt -
Insert one blank line after each line
$ sed G M.log -
Insert two blank lines
$ sed 'G;G' M.log -
Delete blank lines and insert one blank line after each line
$ sed '/^$/d;G' M.log -
Insert a black line above every line which matches pattern
$ sed '/love/{x;p;x;}' M.log -
Insert a black line below every line which matches pattern
$ sed '/love/G' M.log -
Insert 4 spaces to the of every lines
$ sed 's/^/ /' M.log -
Numbering each line of a file (left alignment)
$ sed = M.log | sed 'N;s/\n/\t/' -
Numbering each line of a file (number on left, right-aligned)
$ sed = M.log | sed 'N; s/^/ /; s/ *\(.\{4,\}\)\n/\1 /' -
Numbering each line of a file (only if line is not blank)
$ sed '/./=' M.log | sed '/./N; s/\n/ /'
-
e.g
1:$ chmod ugo-rwx [file_name] -
e.g
2:$ chmod ug+rw,o-x [file_name] -
e.g
3:$ chmod ug=rx,o+r [file_name] -
e.g
4:$ chmod ug+rw,o-x [file_name] -
e.g
5:$ chmod ugo+rwx [file_name] $ chmod 777 [file_name] -
e.g
6:$ chmod u=r,g=wx,o=rx [file_name] $ chmod 435 [file_name] -
e.g
7:$ chmod ug+rwx,o=rx [file_name] $ chmod 775 [file_name]
-
Compress files in a single
.zipfile$ zip [options] zipfile.zip files list -
Extract files from a
.zipfile$ unzip myfile.zipOptions Description -dRemoves the file from the zip archive -uUpdate the specified list of files or add new files to the existing zip file -mDeletes the original files after zipping -rZip a directory recursively -xExclude the files in creating the zip -vVerbose mode
tar [options] [archive-file] [file or directory to be archived]
| Options | Description |
|---|---|
-c |
Creates Archive |
-x |
Extract the archive |
-f |
creates archive with given filename |
-t |
displays or lists files in archived file |
-u |
archives and adds to an existing archive file |
-v |
Displays Verbose Information |
-A |
Concatenates the archive files |
-z |
zip, tells tar command that create tar file using gzip |
-j |
filter archive tar file using tbzip |
-W |
Verify a archive file |
-r |
update or add file or directory in already existed .tar file |
-
Creating an uncompressed
tarArchive.$ tar cvf file.tar *.c -
Extracting files from Archive
$ tar xvf file.tar -
gzipcompression on the tar Archive$ tar cvzf file.tar.gz *.c -
Extracting a gzip tar Archive
*.tar.gz$ tar xvzf file.tar.gz -
Creating compressed tar archive file in Linux
$ tar cvfj file.tar.tbz example.cpp -
Update existing tar file in Linux
$ tar rvf file.tar *.c -
Viewing the Archive
$ tar tvf file.tar >> -rwxrwxrwx root/root 191 2017-09-17 02:20 os2.c >> -rwxrwxrwx root/root 218 2017-09-17 02:20 os3.c >> -rwxrwxrwx root/root 493 2017-09-17 02:20 os4.c
ipcs shows information on the inter-process communication facilities for which the calling process has read access. By default, it shows information about all three resources: shared memory segments, message queues, and semaphore arrays.
Without options, the information shall be written in short format for message queues, shared memory segments, and semaphore sets that are currently active in the system. Otherwise, the information that is displayed is controlled by the options specified.
Safely and reliably make perfect copies of drives, partitions, and filesystems with the Linux dd tool. Whether you're trying to rescue data from a dying storage drive, backing up archives to remote storage, or making a perfect copy of an active partition somewhere else, you'll need to know how to safely and reliably copy drives and filesystems.
- Backup the entire hard disk
-
To backup an entire copy of a hard disk to another hard disk connected to the same system, execute the
ddcommand as shown. In this dd command example, the UNIX device name of the source hard disk is /dev/hda, and device name of the target hard disk is /dev/hdb.$ dd if = /dev/sda of = /dev/sdb
-
Backup a Partition
$ dd if=/dev/sda1 of=~/partition.img
-
Create an image of a hard disk
$ dd if=/dev/sda of=~/sdadisk.img
-
Restore using the hard disk image
$ dd if=hdadisk.img of=/dev/hdb
-
To create CDROM backup
$ dd if=/dev/cdrom of=tgsservice.iso bs=2048
-
A
symbolicorsoft linkis an actual link to the original file. If you delete the original file, the soft link has no value, because it points to a non-existent file.$ ln -s source.file softlink.file -
A
hard linkis a mirror copy of the original file. But hard link, if you delete the original file, the hard link will still has the data of the original file. Because hard link acts as a mirror copy of the original file.$ ln source.file hardlink.file
The crontab is a list of commands that you want to run on a regular schedule. Linux Crontab format:
MIN HOUR DOM MON DOW CMD
| Field | Description | Allowed Value |
|---|---|---|
MIN |
Minute field | 0 to 59 |
HOUR |
Hour field | 0 to 23 |
DOM |
Day of Month | 1 to 31 |
MON |
Month field | 1 to 12 |
DOW |
Day Of Week | 0 to 6 |
CMD |
Command | Any command to be executed. |
- Using Operators
| Operator | Name | Description |
|---|---|---|
* |
asterisk | Stands for all values. Use this operator to keep tasks running during all months, or all days of the week. |
, |
comma | specifies separate individual values. |
- |
dash | Indicates a range of values. |
/ |
forward-slash | Used to divide a value into steps. (*/2 would be every 2 uints, */3 would be every 3 uint, */10 would be every tenth, etc.) |
- Cron special keywords and its meaning
| Keyword | Equivalent |
|---|---|
@reboot |
Run once after reboot. |
@yearly |
Run once a year, ie. 0 0 1 1 * |
@annually |
Run once a year, ie. 0 0 1 1 * |
@monthly |
Run once a month, ie. 0 0 1 * * |
@weekly |
Run once a week, ie. 0 0 * * 0 |
@daily |
Run once a day, ie. 0 0 * * * |
@hourly |
Run once an hour, ie. 0 * * * * |
- Common command
| Command | Description |
|---|---|
crontab -e |
tạo hoặc chỉnh sửa file crontab |
crontab -l |
hiển thị file crontab |
crontab -r |
xóa file crontab |
-
List and sort the file by modification time.
$ ls -t
-
In Reverse order
$ ls -tr
-
Display one file per line
$ ls -1 -
Display all information about files / directories.
$ ls -l >> -rw-rw-r-- 1 m m 7178 Thg 1 3 12:39 Minh_cho.md-
Field explanation:
- Field 1 - File permissions
- Field 2 - Number of links
- Field 3 - Owner
- Field 4 - Group
- Field 5 - Size (in bytes)
- Field 6 - Last modified date and time
- Field 7 - File name
-
Display File UID and GID instead username and group name
$ ls -n >> total 164 >> -rw-rw-r-- 1 1000 1000 1948 Thg 1 3 12:39 add_opencv_to_visual_studio_2019_project.md >> -rw-rw-r-- 1 1000 1000 25081 Thg 1 3 12:39 Error_orcuring_when_install_jetson_nano.md >> -rw-rw-r-- 1 1000 1000 204 Thg 1 3 12:39 hive_sample.txt >> -rw-rw-r-- 1 1000 1000 5099 Thg 1 3 12:39 install_hadoop_hive.md >> -rw-rw-r-- 1 1000 1000 8734 Thg 1 11 01:59 Install_new_linux.md
-
-
Display file size in human readable format
$ ls -lh >> -rw-rw-r-- 1 m m 7,1K Thg 1 3 12:39 Minh_cho.md -
Display directory information
$ ls -ld serial_number/ >> drwxrwxr-x 2 m m 4096 Thg 1 3 12:39 serial_number/ -
Display hidden files
$ ls -la >> total 20 >> drwxrwxr-x 2 m m 4096 Thg 1 3 12:39 . >> drwxrwxr-x 6 m m 4096 Thg 1 11 01:40 .. >> drwxrwxr-x 1 m m 2210 Thg 1 3 12:39 folder >> -rw-rw-r-- 1 m m 4139 Thg 1 3 12:39 serial_number_nano.py >> -rw-rw-r-- 1 m m 64 Thg 1 3 12:39 .unique $ ls -lA >> total 12 >> drwxrwxr-x 1 m m 2210 Thg 1 3 12:39 folder >> -rw-rw-r-- 1 m m 4139 Thg 1 3 12:39 serial_number_nano.py >> -rw-rw-r-- 1 m m 64 Thg 1 3 12:39 .unique -
Display files recursively
$ ls -R
import re
sentence = "Nguyen Hien anh - 06/03/1997, you are so beautiful"
-
Python
reLibraryre's methodsDescription Example re.match(pattern, string, flags=0)Unknown Unknown re.findall(pattern, string, flags=0)Returns a list containing all matches. >>> re.findall('n', sentence)['n', 'n', 'n']re.search(pattern, string, flags=0)Returns A Match object if there is a match anywhere in the string. >>> re.search("\s", sentence)<_sre.SRE_Match object; span=(6, 7), match=' '>re.split()Returns a list where the string has been split at each match. >>> re.split("\s", sentence)['Nguyen', 'Hien', 'anh', '-', '06/03/1997,', 'you', 'are', 'so', 'beautiful']>>> re.split("\s", sentence, 2)['Nguyen', 'Hien', 'anh - 06/03/1997, you are so beautiful']re.sub(pattern, repl, string, flags=0)Replaces one or many matches with a string. >>> re.split("\s", sentence)['Nguyen', 'Hien', 'anh', '-', '06/03/1997,', 'you', 'are', 'so', 'beatiful']match object obj = _sre.SRE_Matchobjectobj.span(): return một tuple (start, stop).obj.start(): start position of the match.obj.stop(): stop position of the match.obj.string(): return the string passed into the function.obj.group(): return the part of string where there was a match. -
repatternre's patternDescription Example [](square brackets)A set of characters. >>> re.findall("[a-m]", sentence)['g', 'e', 'i', 'e', 'a', 'h', 'a', 'e', 'b', 'e', 'a', 'i', 'f', 'l'].(Dot)match bất kỳ ký tự nào ngoại trừ [\n].re.DOTALLflag giúp'.'match bất kỳ ký tự nào kể cả[\n].re.findall('...............', sentence)['Nguyen Hien anh', ' - 06/03/1997, ', 'you are so beau']|Or >>> re.findall("anh|Hien", sentence)['Hien', 'anh']*(Star)Check xem một string có được theo sau bởi 0 hoặc n ký tự. >>> re.findall("en*", 'Nguyen Hiennnn anh - 06/03/1997, you are so beautiful')['en', 'ennnn', 'e', 'e']+(Plus)Check xem một string có được theo sau bởi 1 hoặc n ký tự. >>> re.findall("en+", 'Nguyen Hiennnn anh - 06/03/1997, you are so beautiful')['en', 'ennnn']^(Caret)Starts with >>> re.findall("You are so cute", sentence)[]>>> re.findall("^Nguyen Hien anh", sentence)['Nguyen Hien anh']$Ends with >>> re.findall("ful$", sentence)['ful']{}Check xem một string được theo sau bởi {#}ký tự{#}{#,}{#,#}>>> re.findall("en{1}", 'Nguyen Hiennnn anh - 0>>> re.findall("anh -
Escape characters
re's escape charactersDescription Example r"\A"Starts with >>> re.findall("\AI", sentence)[]>>> re.findall("\ANguyen", sentence)['Nguyen']r"\b"Check xem một match có được bắt đầu hoặc kết thúc bởi các ký tự xác định >>> re.findall(r"en\b", sentence)['en', 'en']>>> re.findall(r"\bNg", sentence)['Ng']>>> re.findall(r"ie\b", sentence)[]r"\B"Check xem một match có xuất hiện nhưng KHÔNG phải bắt đầu hoặc kết thúc. >>> re.findall(r"e\B", sentence)['e', 'e']>>> re.findall(r"\Be", sentence)['e', 'e', 'e']r"\d"Return 1 match chứa string chứa các số từ 0-9>>> re.findall(r"\d", sentence)['0', '6', '0', '3', '1', '9', '9', '7']r"\D"Return 1 match chứa string KHÔNG có các số từ 0-9>>> re.findall(r"\D", sentence)['N', 'g', 'u', 'y', 'e', 'n', ' ', 'H', 'i', 'e', 'n', ' ', 'a', 'n', 'h', ' ', '-', ' ', '/', '/', ',', ' ', 'y', 'o', 'u', ' ', 'a', 'r', 'e', ' ', 's', 'o', ' ', 'b', 'e', 'a', 'u', 't', 'i', 'f', 'u', 'l']r"\s"Return 1 match chứa string chứa các ký tự trắng. "\s"thay thế cho các ký tự[space],[tab],[return].>>> re.findall(r"\s", sentence)[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']r"\S"Return 1 match chứa string KHÔNG chứa ký tự trắng. >>> re.findall(r"\S", sentence)['N', 'g', 'u', 'y', 'e', 'n', 'H', 'i', 'e', 'n', 'a', 'n', 'h', '-', '0', '6', '/', '0', '3', '/', '1', '9', '9', '7', ',', 'y', 'o', 'u', 'a', 'r', 'e', 's', 'o', 'b', 'e', 'a', 'u', 't', 'i', 'f', 'u', 'l']r"\w"Return 1 match chứa string chứa ký tự a-z, A-Z, 0-9 và dấu underscore (_). >>> re.findall(r"\w", sentence)['N', 'g', 'u', 'y', 'e', 'n', 'H', 'i', 'e', 'n', 'a', 'n', 'h', '0', '6', '0', '3', '1', '9', '9', '7', 'y', 'o', 'u', 'a', 'r', 'e', 's', 'o', 'b', 'e', 'a', 'u', 't', 'i', 'f', 'u', 'l']r"\W"Return 1 match chứa string chứa ký tự WORD nào. >>> re.findall(r"\W", sentence)[' ', ' ', ' ', '-', ' ', '/', '/', ',', ' ', ' ', ' ', ' ']r"\Z"Ends with >>> re.findall(r"you are so beautiful\Z", sentence)['you are so beautiful']r"[ae0]"Return 1 match chứa string chứa các ký tự trong class character. >>> re.findall(r"[ae0]", sentence)['e', 'e', 'a', '0', '0', 'a', 'e', 'e', 'a']r"[a-n]"Return 1 match chứa string chứa các ký tự lower case từ a-n.>>> re.findall(r"[a-n]", sentence)['g', 'e', 'n', 'i', 'e', 'n', 'a', 'n', 'h', 'a', 'e', 'b', 'e', 'a', 'f']r"[^NHA]"return 1 match chứa các ký tự NGOẠI TRỪ class character. >>> re.findall(r"[^a-s]", sentence)['N', 'u', 'y', ' ', 'H', ' ', ' ', '-', ' ', '0', '6', '/', '0', '3', '/', '1', '9', '9', '7', ',', ' ', 'y', 'u', ' ', ' ', ' ', 'u', 't', 'u']r"[0-5][0-9]"Return một match từ 00-59.>>> re.findall(r"[0-3][0-9]", sentence)['06', '03', '19']r"[0-37-9]"class character từ 0-3or7-9.>>> re.findall(r"[0-37-9]", sentence)['0', '0', '3', '1', '9', '9', '7']
-
The
grepfilter searches a file for a particular pattern of characters, and displays all lines that contain that pattern.grepstands for Globally search for Regular Expression and Print out)Syntax:
grep [options] pattern [files]Options Description -cThis prints only a count of the lines that match a pattern -hDisplay the matched lines, but do not display the filenames. -iCase insensitive search -lDisplays list of a filenames only. -nDisplay the matched lines and their line numbers. -vThis prints out all the lines that do not matches the pattern -eexpSpecifies expression with this option. Can use multiple times. -ffileTakes patterns from file, one per line. -ETreats pattern as an extended regular expression (ERE) -wMatch whole word -oPrint only the matched parts of a matching line, with each such part on a separate output line. -
Sample Commands
$ cat > geekfile.txt unix is great os. unix is opensource. unix is free os. learn operating system. Unix linux which one you choose. uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
-
Case insensitive search
$ grep -i "UNix" geekfile.txt >> `unix` is great os. `unix` is opensource. `unix` is free os. >> `Unix` linux which one you choose. >> `uNix` is easy to learn.`unix` is a multiuser os.Learn `unix` .`unix` is a powerful. -
Count of line number of matches
$ grep -c "unix" geekfile.txt >> 2 -
Display the file names that matches the pattern
$ grep -l "unix" * >> geekfile.txt $ grep -l "unix" f1.txt f2.txt f3.xt f4.txt geekfile.txt >> geekfile.txt -
Checking for the whole words in a file
$ grep -w "unix" geekfile.txt >> unix is great os. unix is opensource. unix is free os. >> uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. -
Displaying only the matched pattern
$ grep -o "unix" geekfile.txt >> unix >> unix >> unix >> unix >> unix >> unix -
Show line number while displaying the output using grep -n
$ grep -n "unix" geekfile.txt >> 1:unix is great os. unix is opensource. unix is free os. >> 4:uNix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful. -
Inverting the pattern match
$ grep -v "unix" geekfile.txt >> learn operating system. >> Unix linux which one you choose. -
Matching the lines that start with a string
$ grep "^unix" geekfile.txt >> unix is great os. unix is opensource. unix is free os. -
Matching the lines that end with a string
$ grep "os$" geekfile.txt
-
findis a command in Linux to search for files in a directory hierarchy.root@m-K501UX:/home/m# find / -name passwd >> /usr/bin/passwd >> /usr/share/doc/passwd >> /usr/share/bash-completion/completions/passwd >> /usr/share/lintian/overrides/passwd >> /snap/core18/1885/etc/pam.d/passwd >> /snap/core18/1885/etc/passwd >> /snap/core18/1885/usr/bin/passwd >> /snap/core18/1885/usr/share/bash-completion/completions/passwd >> /snap/core18/1885/usr/share/doc/passwd >> /snap/core18/1885/usr/share/lintian/overrides/passwd >> /snap/core18/1885/var/lib/extrausers/passwd >> /etc/cron.daily/passwd >> /etc/pam.d/passwd >> /etc/passwd -
Find the passwd file under root and one level down. (i.e root:level 1, and one sub-directory:level 2)
root@m-K501UX:/home/m# find / -maxdepth 3 -name passwd >> /usr/bin/passwd >> /etc/cron.daily/passwd >> /etc/pam.d/passwd >> /etc/passwd -
Find the password file between sub-directory level 2 and 4.
root@m-K501UX:/home/m# find / -mindepth 3 -maxdepth 4 -name passwd >> /usr/bin/passwd >> /usr/share/doc/passwd >> /etc/cron.daily/passwd >> /etc/pam.d/passwd
Ccrypt is a command line tool for encryption and decryption of data. Ccrypt is based on the Rijndael cipher, the same cipher used in the AES standard. On the other hand, in the AES standard, a 128-bit block size is used, whereas ccrypt uses a 256-bit block size. Ccrypt commonly uses the .cpt file extension for encrypted files.
-
Installation
$ sudo apt-get install ccrypt -
Options
Option Option 2 Description -e--encryptEncrypt -d--decryptDecrypt -c--catDecrypt one or more files to standard output. -x--keychangeChange the key of encrypted data. -u--unixcryptSimulate the old unix crypt command. -
Encrypt file
$ ccrypt M.log >> Enter encryption key: >> Enter encryption key: (repeat) -
Decrypt file
$ ccrypt -d M.log.cpt >> Enter decryption key:
-
ls: list a folder’s contents.$ ls >> add_opencv_to_visual_studio_2019_project.md hive_sample.txt Install_new_linux.md linux-command-GeeksforGeeks.md Minh_cho.md m_yolov4-tensorrt.txt plugins README.md serial_number test-cam-gui >> Error_orcuring_when_install_jetson_nano.md install_hadoop_hive.md install_SMB.md linux_command.md mxnet_server.md note_gstreamer.txt qt.conf reference_FAS.txt serial_number_nano.py -
man: (manual) learn about options and arguments to be used in any command in Linux.man [linux_command]Example:
$ man ls $ man nano -
apropos:apropos [linux_command]Example:
$ apropos rename >> ... >> mv (1) - move (rename) files >> prename (1) - renames multiple files >> rename (2) - change the name or location of a file >> ... -
mv: move or rename files.$ mv oldname newnameas a safe-guard - prevent from overwrite an existing file, always use
-ioption when issuing mv like this.$ mv -i oldname newname -
mkdir: create a subdirectory in your current working directory$ mkdir my_foldercreate a subdirectory (say the directory bar) inside another directory (say the directory foo,
$ mkdir -p ~/foo/bar -
cat: display the contents of a file.$ cat myspeech.txt >> Friends, Coders, Linux-lovers! >> This is an article in GeeksForGeeks. -
less: just view the last few lines of the file.$ less myspeech.txt
-
Shortcut to Directories: You can create a shortcut to frequently accessed directories by adding them to the CDPATH environment variable.
$ export CDPATH=$CDPATH:/home/m/ -
Cursor Movement Control
Control Description Ctrl+aMove cursor to the start of a line Ctrl+eMove cursor to the end of a line Ctrl+◁\▷Navigate word by word Ctrl+wDelete the whole word to the left of the cursor Ctrl+kErase to end of line Ctrl+uErase to beginning of line -
tee- Duplicate pipe content:teeis a very useful utility that append data to multiple existing files at once.$ tee M.log M2.log M3.log -
basename:Strips directory and suffix from filenames.
$ basename /mnt/189633FC5A809F41/6464.txt >> 6464.txt -
ps- Process Status: viewing information related with the processes on a system.Command Description psshows the processes for the current shell ps -A\ps -eview all the running processes -
grep: grep searches files for a given character string or pattern and can replace the string with another. This is one method of searching for files within Linux.grep [option(s)] pattern [file(s)]Example:
$ grep 'Linux' file1 file2 file3
-
Sharing Server
$ python -m http.server 9000 -
Increase Speaker Volume: Increase the maximum volume of your speakers to a certain percentage.
$ pactl set-sink-volume 0 80% -
Fortune Messages: Make your terminal output you random fortune messages.
-
install
fortune$ sudo apt-get install fortune -
run
$ fortune
-
-
Alias command:
-
define all alias to your
.bashrcalias sudo='sudo ' alias pythonM='/home/m/.conda/envs/M/bin/python' alias pipM='/home/m/.conda/envs/M/bin/pip'
-
-
Download accelerator Axel.
-
Axel accelerates HTTP and FTP downloads by using multiple connection to retrieve files from the destination.
-
install
axel$ sudo apt-get install axel
-
-
Current Weather: What about the knowing the current weather of any city around the world.
$ curl http://wttr.in/Hanoi -
Display a calendar and date of Easter
$ cal $ ncal