Useful commands: Difference between revisions

Teeth (talk | contribs)
a few commands 2 get u started
 
Teeth (talk | contribs)
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:


== by category ==
== by category ==
=== navigation ===
{| class="wikitable"
|-
! command !! example !! description
|-
| <code>cd</code> || <code>cd [[#paths|../]]folder/subfolder</code> || '''c'''hange '''d'''irectory from one folder to another
|-
| <code>ls</code> || <code>ls</code> || '''l'''i'''s'''t the contents of a folder
|-
| <code>pwd</code> || <code>pwd</code> || '''p'''rint the full '''w'''orking '''d'''irectory you're currently in
|}
=== media ===
=== media ===
{| class="wikitable"
{| class="wikitable"
Line 13: Line 25:
| <code>yt-dlp</code> || <code>yt-dlp <nowiki>https://youtu.be/INa_SYywZis</nowiki></code> || download videos & audio from [[YouTube]] and [[List of Platforms that pronounmail.com has Outlived|other platforms]]
| <code>yt-dlp</code> || <code>yt-dlp <nowiki>https://youtu.be/INa_SYywZis</nowiki></code> || download videos & audio from [[YouTube]] and [[List of Platforms that pronounmail.com has Outlived|other platforms]]
|}
|}
=== text ===
=== text ===
{| class="wikitable"
{| class="wikitable"
Line 84: Line 97:
| <code>man</code> || <code>man git</code> || command usage details
| <code>man</code> || <code>man git</code> || command usage details
|}
|}
== funky things you can do in the shell ==
the shell has a lot of funky features!!
=== put stuff in a file ===
If you want to take the stuff a command is printing out and instead of printing it out, put it in a file, you can use the <code>></code> symbol. For example, if you wanted to take the last line of a long file and copy it to another file you could do:
<code>tail -n 1 long_file.txt > last_line.txt</code>
Just one <code>></code> will overwrite the file if it already exists. If you use two like this <code>>></code> it will append stuff to the end of the file if it already exists.
=== chain commands together ===
There's a really powerful feature of the shell called "piping" that lets you chain multiple small commands together to do something more complex. You can use the <code>|</code> character for this. For example, if you have a command that prints out a lot of stuff, you can trim it to the last 50 lines and then search for the text "keyword" by chaining commands together like this:
<code>cat long_file.txt | tail -n 50 | grep "keyword"</code>
=== run multiple commands at once ===
You can have one command run only if another one succeeds by chaining them together with <code>&&</code>. If you don't care whether the first command succeeds, you can use <code>;</code> instead.
You can run a command in the background by putting <code>&</code> after it. Just be careful cuz a command running in the background can't be stopped like normal with <code>Ctrl+C</code>. Instead, you'll need to find it's PID and use the <code>kill</code> command.
== paths ==
Every file on a computer has a ''path'' which is how you get there. Imagine we had some folders like this and you're currently hanging out in '''/home/me/folderA'''
{|
|-
| '''/'''
|-
| ↳ || '''home'''
|-
| || ↳ || '''me'''
|-
|colspan="2"| || ↳ || '''folderA'''
|-
|colspan="3"| || ↳ || file1.txt
|-
|colspan="3"| || ↳ || file2.txt
|-
|colspan="2"| || ↳ || folderB
|-
|colspan="3"| || ↳ || file3.txt
|}
Imagine you wanted to print out the contents of '''file3.txt''', there's a few ways you could do this:
<code>cat /home/me/folderB/file3.txt</code> – use the full ''absolute'' path
<code>cat ../folderB/file3.txt</code> – use a path ''relative'' to <code>..</code> the ''parent directory'' right above your current folder which right now, happens to be '''/home/me'''
<code>cat ~/folderB/file3.txt</code> – use a path ''relative'' to <code>~</code> your ''home directory'' which for the user '''me''' will always be '''/home/me'''


[[Category:Pages with some amount of information in them]]
[[Category:Pages with some amount of information in them]]