{"id":346,"date":"2021-08-09T09:24:33","date_gmt":"2021-08-09T12:24:33","guid":{"rendered":"http:\/\/hackerzone.com.br\/blog\/?p=346"},"modified":"2022-08-13T00:26:44","modified_gmt":"2022-08-13T03:26:44","slug":"dicas-de-comando-linux","status":"publish","type":"post","link":"http:\/\/hackerzone.com.br\/blog\/dicas-de-comando-linux\/","title":{"rendered":"Dicas de comando Linux"},"content":{"rendered":"<div class=\"row\">\n<div class=\"col-lg-6\">\n<table class=\"table\">\n<thead>\n<tr>\n<th>File Commands<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>ls<\/strong> &#8211; directory listing<\/td>\n<\/tr>\n<tr>\n<td><strong>ls -al<\/strong> &#8211; formatted listing with hidden files<\/td>\n<\/tr>\n<tr>\n<td><strong>cd dir<\/strong> &#8211; change directory to dir<\/td>\n<\/tr>\n<tr>\n<td><strong>cd<\/strong> &#8211; change to home<\/td>\n<\/tr>\n<tr>\n<td><strong>pwd<\/strong> &#8211; show current directory<\/td>\n<\/tr>\n<tr>\n<td><strong>mkdir dir<\/strong> &#8211; create a diretory dir<\/td>\n<\/tr>\n<tr>\n<td><strong>rm file<\/strong> &#8211; delete file<\/td>\n<\/tr>\n<tr>\n<td><strong>rm -r dir<\/strong> &#8211; delete diretory dir<\/td>\n<\/tr>\n<tr>\n<td><strong>rm -f file<\/strong> &#8211; force remove file<\/td>\n<\/tr>\n<tr>\n<td><strong>rm -rf dir<\/strong> &#8211; force remove directory dir *<\/td>\n<\/tr>\n<tr>\n<td><strong>cp file1 file2<\/strong> &#8211; copy file 1 to file 2<\/td>\n<\/tr>\n<tr>\n<td><strong>cp -r dir1 dir2<\/strong> &#8211; copy dir1 to dir2; create dir2 if it doesn&#8217;t exists.<\/td>\n<\/tr>\n<tr>\n<td><strong>nv file1 file2<\/strong> &#8211; rename or move file1 to file2 if file2 is an existing directory, moves file1 into directory file2<\/td>\n<\/tr>\n<tr>\n<td><strong>ln -s file link<\/strong> &#8211; create symbolic link to file<\/td>\n<\/tr>\n<tr>\n<td><strong>touch file<\/strong> &#8211; create or update file<\/td>\n<\/tr>\n<tr>\n<td><strong>cat > file<\/strong> &#8211; places standard input into file<\/td>\n<\/tr>\n<tr>\n<td><strong>more file<\/strong> &#8211; output the contents of file<\/td>\n<\/tr>\n<tr>\n<td><strong>head file<\/strong> &#8211; output the first 10 lines of file<\/td>\n<\/tr>\n<tr>\n<td><strong>tail file<\/strong> &#8211; output the last 10 lines of file<\/td>\n<\/tr>\n<tr>\n<td><strong>tail -f file<\/strong> &#8211; output the contents of file as it grows, starting with the last 10 lines<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table class=\"table\">\n<thead>\n<tr>\n<th>Process Management<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>ps<\/strong> &#8211; display your currently active processes<\/td>\n<\/tr>\n<tr>\n<td><strong>top<\/strong> &#8211; display all running processes<\/td>\n<\/tr>\n<tr>\n<td><strong>kill pid<\/strong> &#8211; kill process id pid<\/td>\n<\/tr>\n<tr>\n<td><strong>killall proc<\/strong> &#8211; kill all processes named proc*<\/td>\n<\/tr>\n<tr>\n<td><strong>bg<\/strong> &#8211; lists stopped or background jobs; resume a stopped job in the background<\/td>\n<\/tr>\n<tr>\n<td><strong>fg<\/strong> &#8211; brings the most recent job to foreground<\/td>\n<\/tr>\n<tr>\n<td><strong>fg n<\/strong> &#8211; brings job n to the foreground<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table class=\"table\">\n<thead>\n<tr>\n<th>File Permissions<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>chmod octal file<\/strong> &#8211; change the permissions of file to octal, which can be found separately for user, group, and world by adding <\/p>\n<ul>\n<li>4 &#8211; read(r)<\/li>\n<li>2 &#8211; write (w)<\/li>\n<li>1 &#8211; execute(x)<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>Examples<\/td>\n<\/tr>\n<tr>\n<td><strong>chmod 777<\/strong> &#8211; read, write, execute for all<\/td>\n<\/tr>\n<tr>\n<td><strong>chmod 755<\/strong> &#8211; rwx for owner, rx for group and world for more options, see <strong>man chmod<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table class=\"table\">\n<thead>\n<tr>\n<th>SSH<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>ssh user@host<\/strong> &#8211; connect to host as user<\/td>\n<\/tr>\n<tr>\n<td><strong>ssh -p port user@host<\/strong> &#8211; connect to host on port port as user<\/td>\n<\/tr>\n<tr>\n<td><strong>ssh-copy-id user@host<\/strong> &#8211; add your key to host for user to enable a keyed or passwordless login<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table class=\"table\">\n<thead>\n<tr>\n<th>Searching<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>grep pattern files<\/strong> &#8211; search for pattern in files<\/td>\n<\/tr>\n<tr>\n<td><strong>grep -r pattern dir<\/strong> &#8211; search recursively for pattern in dir<\/td>\n<\/tr>\n<tr>\n<td><strong>command | grep pattern<\/strong> &#8211; search for pattern in the output of command<\/td>\n<\/tr>\n<tr>\n<td><strong>locate file<\/strong> &#8211; find all instances of file<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<div class=\"col-lg-6\">\n<table class=\"table\">\n<thead>\n<tr>\n<th>System Info<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>date<\/strong> &#8211; show the current date and time<\/td>\n<\/tr>\n<tr>\n<td><strong>cal<\/strong> &#8211; show this month&#8217;s calendar<\/td>\n<\/tr>\n<tr>\n<td><strong>uptime<\/strong> &#8211; show current uptime<\/td>\n<\/tr>\n<tr>\n<td><strong>w<\/strong> &#8211; display who is online<\/td>\n<\/tr>\n<tr>\n<td><strong>whoami<\/strong> &#8211; who you are logged in as<\/td>\n<\/tr>\n<tr>\n<td><strong>finger user<\/strong> &#8211; display information about user<\/td>\n<\/tr>\n<tr>\n<td><strong>uname -a<\/strong> &#8211; show kernel information<\/td>\n<\/tr>\n<tr>\n<td><strong>cat \/proc\/cpuinfo<\/strong> &#8211; cpu information<\/td>\n<\/tr>\n<tr>\n<td><strong>cat \/proc\/meminfo<\/strong> &#8211; memory information<\/td>\n<\/tr>\n<tr>\n<td><strong>man command<\/strong> &#8211; show the manual for command<\/td>\n<\/tr>\n<tr>\n<td><strong>df<\/strong> &#8211; show disk usage<\/td>\n<\/tr>\n<tr>\n<td><strong>du<\/strong> &#8211; show directory space usage<\/td>\n<\/tr>\n<tr>\n<td><strong>free<\/strong> &#8211; show memory and swap usage<\/td>\n<\/tr>\n<tr>\n<td><strong>whereis app<\/strong> &#8211; show possible locations of app<\/td>\n<\/tr>\n<tr>\n<td><strong>which app<\/strong> &#8211; show which app will be run by default<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table class=\"table\">\n<thead>\n<tr>\n<th>Compression<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>tar cf file.tar files<\/strong> &#8211; create a tar named file.tar containing files<\/td>\n<\/tr>\n<tr>\n<td><strong>tar xf file.tar<\/strong> &#8211; extract the files from file.tar<\/td>\n<\/tr>\n<tr>\n<td><strong>tar czf file.tar.gz files<\/strong> &#8211; create a tar with Gzip compression<\/td>\n<\/tr>\n<tr>\n<td><strong>tar xzf file.tar.gz<\/strong> &#8211; extract a tar using Gzip<\/td>\n<\/tr>\n<tr>\n<td><strong>tar cjf file.tar.bz2<\/strong> &#8211; create a tar with Bzip2 compression<\/td>\n<\/tr>\n<tr>\n<td><strong>tar xjf file.tar.bz2<\/strong> &#8211; extract a tar using Bzip2<\/td>\n<\/tr>\n<tr>\n<td><strong>gzip file<\/strong> &#8211; compresses file and renames it to file.gz<\/td>\n<\/tr>\n<tr>\n<td><strong>gzip -d file.gz<\/strong> &#8211; decompresses file.gz back to file<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table class=\"table\">\n<thead>\n<tr>\n<th>Network<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>ping host<\/strong> &#8211; ping host and output results<\/td>\n<\/tr>\n<tr>\n<td><strong>whois domain<\/strong> &#8211; get whois information for domain<\/td>\n<\/tr>\n<tr>\n<td><strong>dig domain<\/strong> &#8211; get DNS information for domain<\/td>\n<\/tr>\n<tr>\n<td><strong>dig -x host<\/strong> &#8211; reverse lookup host<\/td>\n<\/tr>\n<tr>\n<td><strong>wget file<\/strong> &#8211; download file<\/td>\n<\/tr>\n<tr>\n<td><strong>wget -c file<\/strong> &#8211; continue a stopped download<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table class=\"table\">\n<thead>\n<tr>\n<th>Installation<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Install from source:<\/td>\n<\/tr>\n<tr>\n<td><strong>.\/configure<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>make<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>make install<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>dpkg -i pkg.deb<\/strong> &#8211; install a package (Debian)<\/td>\n<\/tr>\n<tr>\n<td><strong>rpm &#8211; Uvh pkg.rpm<\/strong> &#8211; install a package (RPM)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<table class=\"table\">\n<thead>\n<tr>\n<th>Shortcuts<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Ctrl+C<\/strong> &#8211; halts the current command<\/td>\n<\/tr>\n<tr>\n<td><strong>Ctrl+Z<\/strong> &#8211; stops the current command, resume with <strong>fg<\/strong> in the foreground or <strong>bg<\/strong> in the background<\/td>\n<\/tr>\n<tr>\n<td><strong>Ctrl+D<\/strong> &#8211; log out of current session, similar to <strong>exit<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>Ctrl+W<\/strong> &#8211; erases one word int the current line<\/td>\n<\/tr>\n<tr>\n<td><strong>Ctrl+U<\/strong> &#8211; erases the whole line<\/td>\n<\/tr>\n<tr>\n<td><strong>Ctrl+R<\/strong> &#8211; type to bring up a recent command<\/td>\n<\/tr>\n<tr>\n<td><strong>!!<\/strong> &#8211; repeats the last command.<\/td>\n<\/tr>\n<tr>\n<td><strong>exit<\/strong> &#8211; log out of current session<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>File Commands ls &#8211; directory listing ls -al &#8211; formatted listing with hidden files cd dir &#8211; change directory to dir cd &#8211; change to home pwd &#8211; show current directory mkdir dir &#8211; create a diretory dir rm file &#8211; delete file rm -r dir &#8211; delete diretory dir rm -f file &#8211; force [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":460,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41,3,2],"tags":[158,7,159],"class_list":["post-346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-fedora","category-linux","tag-comandos","tag-linux","tag-principais-comandos","cat-41-id","cat-3-id","cat-2-id","has_thumb"],"_links":{"self":[{"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/posts\/346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/comments?post=346"}],"version-history":[{"count":1,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions"}],"predecessor-version":[{"id":348,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions\/348"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/media\/460"}],"wp:attachment":[{"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/media?parent=346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/categories?post=346"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/hackerzone.com.br\/blog\/wp-json\/wp\/v2\/tags?post=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}