Lately, I started learning commands lines. I mean, I used npm install or gulp, but no more.
So I started using commands lines and I have to say th...
For further actions, you may consider blocking this person and/or reporting abuse
If you're finding yourself attacking those annoying commands often, consider setting an alias for them!
Instead of typing
ls -AbcClhoG, you could alias all that intoll.First thing's first, assuming you're using
bash/shand notzshor variants (usewhich $SHELLto figure that out!), runnano ~/.bashrcto start editing your config for the shell.You'll then want to add an alias at the bottom now, using
alias ll="ls -AbcClhoG". Easy!Ctrl + C, Y, Yto save and exit nano, and you'll want tosource ~/.bashrcor make a new tab in Terminal to reload your settings.You can run any commands and name them however you want - even chaining them as you go.
command & commandwill run them concurrently, whilstcommand && commandwill run each individually assuming the last command succeeds.command &will leave the task running indefinitely, so be careful (you can alwaysCtrl + Cout of it).Or you can press
Ctrl + Zafter you docommand &to run it as a background job.Using
openlike that is an OS X/macOS thing -- the FreeDesktop.org standard most Linux distributions adhere to is to usexdg-open.On Linux, the
opencommand handles virtual terminals.Oh thank you, I didn't know. I note it
Nice post! Just a note though,
opencommand is a little different between Mac OS and Linux distributions. Linux equivalent isxdg-open.Edit: You guys already noticed it :(
You mentioned the -p flag for rmdir. It can also be used with mkdir, as 'mkdir x/y/z'.
As a few people have mentioned, you can add aliases in your ~/.bashrc.
My favorite is:
mkdcd() {
mkdir $1
cd $1
}
Which makes creating and changing your cwd easy.
And also: cd.. for cd ..
grepis awesome way to search for stuff.Particularly when combined with
|operator to chain stuff.For example,
ls | grep my_file.txtGreat post Jérémy!
Some more:
ps auxwill show you the running processes.netstatwill show you the open network ports.Both of these will have a very large output, so combine with
grepto filter for a specific string:$ ps aux | grep mysqlis a good way to see what process represents a MySQL instance, for example.NOTE: the
$is conventionally used to represent the start of a command you type into your bash terminal and run withreturnorenter. You don't type out the$character.This is useful when your application is not running as expected and you want to check than any requried processes have been started.
You can use this to figure out what is running on a particular port (and kill it if desired):
stackoverflow.com/questions/115835...
I end up using these a lot when working with introductory web development students -- they don't know how to check what is running, end up starting 2 or more instances of a server process, and then get confused when they can't connect to their web application.
Awesome start Jeremy. When I played with Unix terminal for the first time, I made a major mistake which was not going over the basics.
Add these especially if you are in a directory
cd ..takes you backcd -takes you to the previous directoryls -shlists the files/directories with their sizesls -llists the details including permissions.There are lots more, but add these to yours
Have fun in your journey!
If you want to check a file quickly without having to deal with
vim/emacs/nanoand it's too long to usecat/echo,moreis really useful but it only reads in one direction. For both directions check outlessto read both directionsI really do love
tar -xfv test.tarandls -lisaIf you find your self puzzled by the various archive extensions then this is for you. Linux CLI unpack unification script.
pastebin.com/wNCP166T
(Excuse the shameless plug btw)
I typically use ls -lart :) (the a isn't necessary but it is appropriate ;) )
I understand why you do that and it spoils it a little to add a letter - but my only common use case apart from a normal
lsisls -larth.If I understand correctly, you can chain options?
-xfvmeans-x, then-f, then-v, is it correct?This is correct (of most commands)! Some more complex ones can't be chained.
For example, you can't chain
--this-is-an-argand--this-too-is-an-argbut individual letters are usually fine.Some time ago, I build a .sh where I put all my little scripts to semi-automitize some task: open certain programs with my configs, create my projects with git and makefile, update/upgrade my system, compress files... Other more complex to remember, like connecting to an external monitor via VGA/HDMI. 15 or 20 lil'scripts to make my life easier. Why? If there is a easiest way to do something, I will choose it.
save yourself.
unlearn rmdir.
now.
There's something wrong with
rmdir?nope, nothing at all
my bad
I saw "rmdir" and read "rm -rf"
rm -rfdoes incredible and irreparable damage except you have backups handy.You can't restore a backup if you
rm -rf /.Exactly. You just wiped out the entire system..
Well except if you have an external backup of some sort. 😏
I'd like to recommend this NPM module: npmjs.com/package/tldr
It's basically like the 'man' command, but usually with a shorter description and example uses. For example, 'tldr tar' will tell you which flag combination you need to extract different types of compressed archives.
And I'll add another few commands that I use daily:
| When you want to delete a non-empty directory, use with caution!ls -a | Basically like ls, but also displays hidden files.
rm -rf
mkdir dir/{subdir1,subdir2} | Use curly braces to create multiple subdirs at once.
cd | Just typing cd is the same as 'cd ~', which brings you to your home directory.
cat | Will print to contents of a file to the console, so you don't have to open the file just to view it.
Also, check out your .bashrc by typing cat ~/.bashrc, in there you'll find several bash aliases, as well as having the possibility to create your own.
And again, don't use rm -rf, if you're not 100% certain that you know what you're doing.
The find command is one of the most useful on your toolkit
find . -exec cp {} . \;
(Recusevely find all files in a path and copy to the root)
Although you should really be using fd
I think
catandwhichare extremely usefulOh
whichcommand is very useful indeed, especially on macOS where paths are hidden. Thanks, I discovered!Oh yeah, good to know, thanks!
how to delete all the records in the file at a time retaining the file / folder