# Kali Linux cmd :::success [TOC] ::: #### Basic - Display present working location ```shell= # print work directory pwd ``` - list all items in the current directory ```shell= # list ls # -l 列出詳細資料 # -a 列出隱藏資料 ls -la # 列出部分檔案: *.XXX ls *.py ``` - change current directory ```shell= # change directory cd <directory> # ~ 家目錄 # .. 上一層 # / 根目錄 ``` - find word in a file ```shell= grep <keyword> <filename> ``` - create new directory ```shell= # make directory mkdir <directory_name> ``` - remove directory ```shell= rmdir <directory_name> ``` - move files ```shell= # move mv <file_name> <new_directory> # rename mv <origin_file_name> <new_file_name> ``` - remove files ```shell= # remove rm <file_name> # remove .XXX files rm *.py # remove folder & files rm -f <folder_name> ``` - find file ```shell= find <path> -name <file_name> ``` - copy a file ```shell= # copy cp <file_name> <new_directory> ``` - create new file ```shell= # update timestamp / create new file touch <file_name> ``` - display manual of cmd ```shell= man <cmd> ``` - check host status ```shell= ping <url> # check path from localhost to server traceroute <url> # check DNS response nslookup <url> ``` - display network inference details ```shell= ifconfig ``` - download a file ```shell= wget <link_to_file> ``` - check file content ```shell= cat <file_name> ``` - check content back of the file ```shell= tail <file_name> # 持續更新內容(server log) tail -f <file_name> ``` - print file into pages ```shell= more <file_name> ``` - check file format ```shell= file <file_name> ``` - edit file ```shell= # create/edit inside terminal nano <file_name> // ctrl + X exit // ctrl + V page up // ctrl + Y page down // ctrl + W search text content # edit inside terminal vim <file_name> // i edit mode // esc exit edit mode // :q quit without save // :wq save and quit // :q! forced quit ``` - install a package ```shell= sudo apt install <package_name> ``` - remove a package ```shell= sudo apt remove <package_name> ``` - upgrade package in sys ```shell= sudo apt upgrade ``` - fetch packages upgrade ```shell= sudo apt update ``` - get current user name ```shell= whoami ``` - change current user to superuser or root ```shell= sudo su ``` - print in terminal ```shell= echo "<text>" # write text in file echo "<text>" > <file> ``` - unzip file ```shell= unzip <file_name> ``` - give file permission ```shell= #add permission(execute) chmod +x <file_name> #add permission(read) chmod +r <file_name> #add permission(write) chmod +w <file_name> #remove permission(execute) chmod -x <file_name> #remove permission(read) chmod -r <file_name> #remove permission(write) chmod -w <file_name> ``` - daily task ```shell= # edit crontab -e # format minute/hour/day/month/week/cmd 30 12 * * * python3 /helloWorld.py & ``` - image details reader ```shell= exiftool <file_name> ``` - base64 encode/decode ```shell= # decode code => string echo "SSBsdXYgVQo=" | base64 -d # encode string => code echo "I luv U" | base64 ``` #### curl - source code ```shell= curl <url> ``` - download image ```shell= curl -o <file_name> <url> # rename it as url curl -O <url> # continued the paused task curl -C - -O <url> ``` - 301/302 redirect ```shell= curl -L <url> # track curl --trace-ascii <file_name> <url> ``` - post ```shell= curl -I <url> curl -X POST <url> curl -X POST --data "<content_type>" <url> curl -X POST -F '<file>' <url> ``` - get ```shell= curl -X GET <url> ``` - put ```shell= curl -X PUT -H <content_type> -d <data> <url> ``` - delete ```shell= curl -X DELETE <url> ``` - cookie ```shell= curl --cookie <data> <url> ``` - user agent ```shell= curl --user-agent <Agent> <url> curl --user-agent "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)" http://www.example.com ``` - basic Authentication ```shell= curl -i --user secret:vary_secret http://www.example.com/api/resources ``` #### Netcat - check host connection ```shell= nc -v <host> ``` - connect to host's port ```shell= nc <host> <port> ``` more about nc :point_down: :::spoiler https://blog.gtwang.org/linux/linux-utility-netcat-examples/ :::