Make your own linux command??
Ok so I have no clue where to post this so I am asking in programming.
I am learning python on linux and I find myself doing this command a lot:
clear && ls
I like doing this so that my terminal looks a lot more cleaner after all my testing. After doing this command a thousand of times I made a little .sh file with this command In it but I would like to be able to do this command In one shot. I meen that I would prefer to type just one small command instead of clear && ls
or \. clear. sh (no spaces)
If you don’t get what I mean, I am just trying to create my own linux command that clears the terminal and then lists the files of the current directory :)
Please help
Used to be lexostras…. but i got tierd of my name so now it’s worst…..
My github dont click this
9 years ago | edited 9 years ago
0
To achieve that you can simply create bash script and put it in one of paths folders.
Script:
#!/bin/sh
clear && ls
Save it as command_name.sh file and change its permissions to 755 (chmod 755 filename), then in your terminal echo $PATH variable to see in which folders you can put your file to act like “command”, after that just move your script to one of folders in $PATH variable, e.g. /usr/local/bin
You may also need to use sudo command sometimes during this process. To call that script file you only have to write command_name from command_name.sh
Thanks a lot @souvarine :) I jsut did it. Do you know why wen I do the normal command ls some files appear with diferent colors but when I do it with the command that I made the files are all of the same color
Used to be lexostras…. but i got tierd of my name so now it’s worst…..
My github dont click this
9 years ago | edited 9 years ago
0
@lexostras, to colorize the output when calling ‘ls’ from script, you should add –color=always parameter, then your command shoud look like this:
clear && ls --color=always
Problem is that “ls” has different default values when called directly from terminal emulator and from script file.
Another option is using ‘alias’:
alias cls='clear && ls'
You can add this to your ‘.bashrc’ if you like.
If you look in ‘.bashrc’, you’ll also see why doing it with that little script doesn’t work in the same way. The command ‘ls’ is made an alias for ‘ls –color’ (or something similar), but only when running interactively, which a script is not.
thank you @dloser do you know a good reference to make scipts like that one that I am making because I am having a lot of fun here :) and I tried out the alias cls='clear && ls'
but when I restart the teminal It does not work and when I put your code in the file that I made for the command, It does not work. Do you know a way to change that??
Used to be lexostras…. but i got tierd of my name so now it’s worst…..
My github dont click this
ok thanks @nakee
Used to be lexostras…. but i got tierd of my name so now it’s worst…..
My github dont click this
@nakee : I am a visual learner. That’s how I learn. I just posted the video cause it might help @lexostras in answering the questions that he/she has.
A beginner practices until he gets it right, a professional practices until he can’t get it wrong!
Used to be lexostras…. but i got tierd of my name so now it’s worst…..
My github dont click this