{"id":45,"date":"2023-02-06T18:30:32","date_gmt":"2023-02-06T18:30:32","guid":{"rendered":"http:\/\/130.61.23.153\/install\/?page_id=45"},"modified":"2024-03-17T13:31:23","modified_gmt":"2024-03-17T13:31:23","slug":"commands","status":"publish","type":"page","link":"https:\/\/slavy.site\/index.php\/commands\/","title":{"rendered":"Commands"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>whoami - who am I\npwd - where am I\nadduser - add user\nsudo kill -9 pidNr - kill 100% the process\nusermod -aG sudo slavy - add user slavy to sudo users\nchown slavy:slavy \/home\/test change ownership on folder \/home\/test to user slavy and group slavy\nchmod 755 \/home\/test - give permissions 755 on \/home\/test\nls -altr - list includes hidwp-admin\/post.php?post=52&amp;action=editen files and folders\nifconfig - Display network interfaces and IP addresses\nwget - Direct download files from the internet \nufw - Firewall command\nsudo ufw status numbered - list all open ports\nmkdir \/home\/test - create folder \/home\/test\nmv \/home\/test \/home\/test2 - change name to folder<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>du -hs \/path\/to\/directory - dir size\ndu -h --max-depth=1 \/path\/to\/directory<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Linux Terminal Command Reference<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>System Info<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>date \u2013 Show the current date and time\ncal \u2013 Show this month's calendar\nuptime \u2013 Show current uptime\nw \u2013 Display who is online\nwhoami \u2013 Who you are logged in as\nfinger user \u2013 Display information about user\nuname -a \u2013 Show kernel information\ncat \/proc\/cpuinfo \u2013 CPU information\ncat \/proc\/meminfo \u2013 Memory information\ndf \u2013 Show disk usage\ndu \u2013 Show directory space usage\nfree \u2013 Show memory and swap usage<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Keyboard Shortcuts<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Enter \u2013 Run the command\nUp Arrow \u2013 Show the previous command\nCtrl + R \u2013 Allows you to type a part of the command you're looking for and finds it\n\nCtrl + Z \u2013 Stops the current command, resume with fg in the foreground or bg in the background\nCtrl + C \u2013 Halts the current command, cancel the current operation and\/or start with a fresh new line\nCtrl + L \u2013 Clear the screen\n\ncommand | less \u2013 Allows the scrolling of the bash command window using Shift + Up Arrow and Shift + Down Arrow\n!! \u2013 Repeats the last command\ncommand !$ \u2013 Repeats the last argument of the previous command\nEsc + . (a period) \u2013 Insert the last argument of the previous command on the fly, which enables you to edit it before executing the command\n\nCtrl + A \u2013 Return to the start of the command you're typing\nCtrl + E \u2013 Go to the end of the command you're typing\nCtrl + U \u2013 Cut everything before the cursor to a special clipboard, erases the whole line\nCtrl + K \u2013 Cut everything after the cursor to a special clipboard\nCtrl + Y \u2013 Paste from the special clipboard that Ctrl + U and Ctrl + K save their data to\nCtrl + T \u2013 Swap the two characters before the cursor (you can actually use this to transport a character from the left to the right, try it!)\nCtrl + W \u2013 Delete the word \/ argument left of the cursor in the current line\n\nCtrl + D \u2013 Log out of current session, similar to exit<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Learn the Commands<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apropos subject \u2013 List manual pages for subject\nman -k keyword \u2013 Display man pages containing keyword\nman command \u2013 Show the manual for command\nman -t man | ps2pdf - &gt; man.pdf \u2013 Make a pdf of a manual page\nwhich command \u2013 Show full path name of command\ntime command \u2013 See how long a command takes\n\nwhereis app \u2013 Show possible locations of app\nwhich app \u2013 Show which app will be run by default; it shows the full path<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Searching<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep pattern files \u2013 Search for pattern in files\ngrep -r pattern dir \u2013 Search recursively for pattern in dir\ncommand | grep pattern \u2013 Search for pattern in the output of command\nlocate file \u2013 Find all instances of file\nfind \/ -name filename \u2013 Starting with the root directory, look for the file calledifconfig - Display network interfaces and IP addresses filename\nfind \/ -name \u201d<em>filename<\/em>\u201d \u2013 Starting with the root directory, look for the file containing the string filename\nlocate filename \u2013 Find a file called filename using the locate command; this assumes you have already used the command updatedb (see next)\nupdatedb \u2013 Create or update the database of files on all file systems attached to the Linux root directory\nwhich filename \u2013 Show the subdirectory containing the executable file called filename\ngrep TextStringToFind \/dir \u2013 Starting with the directory called dir, look for and list all files containing TextStringToFind<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>File Permissions<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod octal file \u2013 Change the permissions of file to octal, which can be found separately for user, group, and world by adding: 4 \u2013 read (r), 2 \u2013 write (w), 1 \u2013 execute (x)\nExamples:\nchmod 777 \u2013 read, write, execute for all\nchmod 755 \u2013 rwx for owner, rx for group and world\nFor more options, see man chmod.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>File Commands<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls \u2013 Directory listing\nls -l \u2013 List files in current directory using long format\nls -laC \u2013 List all files in current directory in long format and display in columns\nls -F \u2013 List files in current directory and indicate the file type\nls -al \u2013 Formatted listing with hidden files\n\ncd dir \u2013 Change directory to dir\ncd \u2013 Change to home\nmkdir dir \u2013 Create a directory dir\npwd \u2013 Show current directory\n\nrm name \u2013 Remove a file or directory called name\nrm -r dir \u2013 Delete directory dir\nrm -f file \u2013 Force remove file\nrm -rf dir \u2013 Force remove an entire directory dir and all it\u2019s included files and subdirectories (use with extreme caution)\n\ncp file1 file2 \u2013 Copy file1 to file2\ncp -r dir1 dir2 \u2013 Copy dir1 to dir2; create dir2 if it doesn't exist\ncp file \/home\/dirname \u2013 Copy the file called filename to the \/home\/dirname directory\n\nmv file \/home\/dirname \u2013 Move the file called filename to the \/home\/dirname directory\nmv file1 file2 \u2013 Rename or move file1 to file2; if file2 is an existing directory, moves file1 into directory file2\n\nln -s file link \u2013 Create symbolic link link to file\ntouch file \u2013 Create or update file\ncat &gt; file \u2013 Places standard input into file\ncat file \u2013 Display the file called file\n\nmore file \u2013 Display the file called file one page at a time, proceed to next page using the spacebar\nhead file \u2013 Output the first 10 lines of file\nhead -20 file \u2013 Display the first 20 lines of the file called file\ntail file \u2013 Output the last 10 lines of file\ntail -20 file \u2013 Display the last 20 lines of the file called file\ntail -f file \u2013 Output the contents of file as it grows, starting with the last 10 lines<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Compression<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>tar cf file.tar files \u2013 Create a tar named file.tar containing files\ntar xf file.tar \u2013 Extract the files from file.tar\n\ntar czf file.tar.gz files \u2013 Create a tar with Gzip compression\ntar xzf file.tar.gz \u2013 Extract a tar using Gzip\n\ntar cjf file.tar.bz2 \u2013 Create a tar with Bzip2 compression\ntar xjf file.tar.bz2 \u2013 Extract a tar using Bzip2\n\ngzip file \u2013 Compresses file and renames it to file.gz\ngzip -d file.gz \u2013 Decompresses file.gz back to file<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Printing<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/etc\/rc.d\/init.d\/lpd start \u2013 Start the print daemon\n\/etc\/rc.d\/init.d\/lpd stop \u2013 Stop the print daemon\n\/etc\/rc.d\/init.d\/lpd status \u2013 Display status of the print daemon\nlpq \u2013 Display jobs in print queue\nlprm \u2013 Remove jobs from queue\nlpr \u2013 Print a file\nlpc \u2013 Printer control tool\nman subject | lpr \u2013 Print the manual page called subject as plain text\nman -t subject | lpr \u2013 Print the manual page called subject as Postscript output\nprinttool \u2013 Start X printer setup interface<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Network<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ifconfig \u2013 List IP addresses for all devices on the local machine\nping host \u2013 Ping host and output results\nwhois domain \u2013 Get whois information for domain\ndig domain \u2013 Get DNS information for domain\ndig -x host \u2013 Reverse lookup host\nwget file \u2013 Download file\nwget -c file \u2013 Continue a stopped download<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>SSH<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh user@host \u2013 Connect to host as user\nssh -p port user@host \u2013 Connect to host on port port as user\nssh-copy-id user@host \u2013 Add your key to host for user to enable a keyed or passwordless login<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>User Administration<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>adduser accountname \u2013 Create a new user call accountname\npasswd accountname \u2013 Give accountname a new password\nsu \u2013 Log in as superuser from current login\nexit \u2013 Stop being superuser and revert to normal user<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Process Management<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ps \u2013 Display your currently active processes\ntop \u2013 Display all running processes\nkill pid \u2013 Kill process id pid\nkillall proc \u2013 Kill all processes named proc (use with extreme caution)\nbg \u2013 Lists stopped or background jobs; resume a stopped job in the background\nfg \u2013 Brings the most recent job to foreground\nfg n \u2013 Brings job n to the foreground<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Installation from source<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/configure\nmake\nmake install\ndpkg -i pkg.deb \u2013 install a DEB package (Debian \/ Ubuntu \/ Linux Mint)\nrpm -Uvh pkg.rpm \u2013 install a RPM package (Red Hat \/ Fedora)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Stopping &amp; Starting<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>shutdown -h now \u2013 Shutdown the system now and do not reboot\nhalt \u2013 Stop all processes - same as above\nshutdown -r 5 \u2013 Shutdown the system in 5 minutes and reboot\nshutdown -r now \u2013 Shutdown the system now and reboot\nreboot \u2013 Stop all processes and then reboot - same as above\nstartx \u2013 Start the X system<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>lsusb - \u043b\u0438\u0441\u0442\u0432\u0430\u043d\u0435 \u043d\u0430 \u0432\u0441\u0438\u0447\u043a\u0438 usb \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\nfdisk -l \u043b\u0438\u0441\u0442\u0432\u0430\u043d\u0435 \u043d\u0430 \u0432\u0441\u0438\u0447\u043a\u0438 \u0434\u0438\u0441\u043a\u043e\u0432\u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430\nethtool enp3s0 - \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0437\u0430 lan \u043a\u0430\u0440\u0442\u0430\nsmartctl - \u0441\u043c\u0430\u0440\u0442 \u0447\u0435\u043a \u043d\u0430 \u0434\u0438\u0441\u043a<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.hivelocity.net\/kb\/how-to-check-if-your-linux-server-is-under-ddos-attack-2\/\" data-type=\"link\" data-id=\"https:\/\/www.hivelocity.net\/kb\/how-to-check-if-your-linux-server-is-under-ddos-attack-2\/\">How to Check if Your Linux Server Is Under DDoS Attack<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep processor \/proc\/cpuinfo | wc -l uptime - determine your server\u2019s current load\n\nnetstat -ntu|awk '{print $5}'|cut -d: -f1 -s|sort|uniq -c|sort -nk1 -r - this command will return a descending list of which IPs are connected to your server and how many connections each one has\n\nnetstat -ntu|awk '{print $5}'|cut -d: -f1 -s |cut -f1,2 -d'.'|sed 's\/$\/.0.0\/'|sort|uniq -c|sort -nk1 -r - you\u2019ll want to determine if these connections are coming from common subnets<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Linux Terminal Command Reference System Info Keyboard Shortcuts Learn the Commands Searching File Permissions File Commands Compression Printing Network SSH<\/p>\n<p><a href=\"https:\/\/slavy.site\/index.php\/commands\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\">Commands<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-45","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/slavy.site\/index.php\/wp-json\/wp\/v2\/pages\/45","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/slavy.site\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/slavy.site\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/slavy.site\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/slavy.site\/index.php\/wp-json\/wp\/v2\/comments?post=45"}],"version-history":[{"count":20,"href":"https:\/\/slavy.site\/index.php\/wp-json\/wp\/v2\/pages\/45\/revisions"}],"predecessor-version":[{"id":342,"href":"https:\/\/slavy.site\/index.php\/wp-json\/wp\/v2\/pages\/45\/revisions\/342"}],"wp:attachment":[{"href":"https:\/\/slavy.site\/index.php\/wp-json\/wp\/v2\/media?parent=45"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}