Please help me out, i am new. "ls" command for list doesn't work on my Node.js most times. It is not working now. However, it works sometimes though. How can i find list of current directory or file in Node.js?
As per to my tutorial for Node.js, i have to use command "ls" to see the list of my current directory or file.
When i press enter on ""ls" it replied "ls" is not found as internal or external command."
However, "ls" command shows the contents of file sometimes. I am using "ls" command for Desktop listing and another file in their. I do go to Desktop by cd Desktop. and then i only write "ls" then enter.
Please reply with simple explanation since i am new and learning Node.js.
i am taking Essential Node.js training from Lynda.com. "ls" did worked earlier though. "ls" does work on Window Shell and Bash all the time. Please reply. Thank You.
If not, what command i shall use for listing current directory or file contents?
Windows operational system provides the command dir instead of ls which should work similarly in your case:
Just use:
dir
Related
this question is pretty fundamental but i didn't find the right words to google to find an answer
i want to start a presentation on a raspberry pi straight when it boots
So i tested the command to get it to open my presentation, i just used this command:
sudo libreoffice --impress --nolockcheck --nologo --norestore --show /home/pi/Desktop/Praesentation/1.pptx
that worked so i put that line into the autostart file at this path:
/etc/xdg/lxsession/LXDE-pi/autostart
That works fine but i found out that you should or can also use this command in the file:
#libreoffice --impress --nolockcheck --nologo --norestore --show /home/pi/Desktop/Praesentation/1.pptx
but running the command in the commandline with bash #libreoffice... does not work
What does the # mean?
I'm pretty sure you shouldn't be running LibreOffice as root (sudo). This will give it full rights to do anything on the system, which is not needed for an office application, and it might cause all sorts of trouble if it writes files owned by the wrong user.
The LXSession wiki explains what the # means:
autostart configuration file
This file stores the commands that will be executed at the beginning of the session. It is not a shell script, but each line represents a different command to be executed. If a line begins with #, the command following the # will be automatically re-executed if it crashes.
I am trying to code on Colab and if I take a look at the code its self similar with linux, therefore I am asking how the commands work on linux.
I am still confused the why cd on linux works. If I have code like this
cd A/B
it means to create new directory right?
after the first code then I write this
!wget https://abcd.com
does it mean I download file from https://abcd.com and store it at B path?
cd does not create anything, it just changes your shell's current working directory.
The ! in your next command is a bit weird, too. It indicates a history expansion of the most recent command line in your shell history starting with wget, adding https://abcd.com to that command line and then running it. That could be pretty much anything, depending on what your shell history contains.
So I am not experienced in dealing with a plethora of file types, and I haven't been able to find much info on exactly what .sh files are. Here's what I'm trying to do:
I'm trying to download map data sets which are arranged in tiles that can be downloaded individually: http://daymet.ornl.gov/gridded
In order to download a range of tiles at once, they say to download their script, which eventually leads to daymet-nc-retrieval.sh: https://github.com/daymet/scripts/blob/master/Bash/daymet-nc-retrieval.sh
So, what exactly am I supposed to do with this code? The website doesn't provide further instructions, assuming users know what to do with it. I'm guessing you're supposed to paste the code in to some other unmentioned application for a browser (using Chrome or Firefox in this case)? It almost looks like something that could be pasted in to Firefox/Greasemonkey, but not quite. Just by a quick Google on the file type I haven't been able to get heads or tails on it.
I'm sure there's a simple explanation on what to do with these files out there, but it seems to be buried in plenty of posts where people are already assuming you know what to do with these files. Anyone willing to just simply say what needs to be done from square one after getting to the page with the code to actually implementing it? Thanks.
What is a file with extension .sh?
It is a Bourne shell script. They are used in many variations of UNIX-like operating systems. They have no "language" and are interpreted by your shell (interpreter of terminal commands) or if the first line is in the form
#!/path/to/interpreter
they will use that particular interpreter. Your file has the first line:
#!/bin/bash
and that means that it uses Bourne Again Shell, so called bash. It is for all practical purposes a replacement for good old sh.
Depending upon the interpreter you will have different languages in which the file is written.
Keep in mind, that in UNIX world, it is not the extension of the file that determines what the file is (see "How to execute a shell script" below).
If you come from the world of DOS/Windows, you will be familiar with files that have .bat or .cmd extensions (batch files). They are not similar in content, but are akin in design.
How to execute a shell script
Unlike some unsafe operating systems, *nix does not rely exclusively on extensions to determine what to do with a file. Permissions are also used. This means that if you attempt to run the shell script after downloading it, it will be the same as trying to "run" any text file. The ".sh" extension is there only for your convenience to recognize that file.
You will need to make the file executable. Let's assume that you have downloaded your file as file.sh, you can then run in your terminal:
chmod +x file.sh
chmod is a command for changing file's permissions, +x sets execute permissions (in this case for everybody) and finally you have your file name.
You can also do it in your GUI. Most of the time you can right click on the file and select properties; in XUbuntu the permissions options look like this:
If you do not wish to change the permissions, you can also force the shell to run the command. In the terminal you can run:
bash file.sh
The shell should be the same as in the first line of your script.
How safe is it?
You may find it weird that you must perform another task manually in order to execute a file. But this is partially because of a strong need for security.
Basically when you download and run a bash script, it is the same thing as somebody telling you "run all these commands in sequence on your computer, I promise that the results will be good and safe". Ask yourself if you trust the party that has supplied this file, ask yourself if you are sure that you have downloaded the file from the same place as you thought, maybe even have a glance inside to see if something looks out of place (although that requires that you know something about *nix commands and bash programming).
Unfortunately apart from the warning above I cannot give a step-by-step description of what you should do to prevent evil things from happening with your computer; so just keep in mind that any time you get and run an executable file from someone you're actually saying, "Sure, you can use my computer to do something".
If you open your second link in a browser you'll see the source code:
#!/bin/bash
# Script to download individual .nc files from the ORNL
# Daymet server at: http://daymet.ornl.gov
[...]
# For ranges use {start..end}
# for individul vaules, use: 1 2 3 4
for year in {2002..2003}
do
for tile in {1159..1160}
do wget --limit-rate=3m http://daymet.ornl.gov/thredds/fileServer/allcf/${year}/${tile}_${year}/vp.nc -O ${tile}_${year}_vp.nc
# An example using curl instead of wget
#do curl --limit-rate 3M -o ${tile}_${year}_vp.nc http://daymet.ornl.gov/thredds/fileServer/allcf/${year}/${tile}_${year}/vp.nc
done
done
So it's a bash script. Got Linux?
In any case, the script is nothing but a series of HTTP retrievals. Both wget and curl are available for most operating systems and almost all language have HTTP libraries so it's fairly trivial to rewrite in any other technology. There're also some Windows ports of bash itself (git includes one). Last but not least, Windows 10 now has native support for Linux binaries.
sh files are unix (linux) shell executables files, they are the equivalent (but much more powerful) of bat files on windows.
So you need to run it from a linux console, just typing its name the same you do with bat files on windows.
Typically a .sh file is a shell script which you can execute in a terminal. Specifically, the script you mentioned is a bash script, which you can see if you open the file and look in the first line of the file, which is called the shebang or magic line.
I know this is an old question and I probably won't help, but many Linux distributions(e.g., ubuntu) have a "Live cd/usb" function, so if you really need to run this script, you could try booting your computer into Linux. Just burn a .iso to a flash drive (here's how http://goo.gl/U1wLYA), start your computer with the drive plugged in, and press the F key for boot menu. If you choose "...USB...", you will boot into the OS you just put on the drive.
How do I run .sh scripts?
Give execute permission to your script:
chmod +x /path/to/yourscript.sh
And to run your script:
/path/to/yourscript.sh
Since . refers to the current directory: if yourscript.sh is in the current directory, you can simplify this to:
./yourscript.sh
or with GUI
https://askubuntu.com/questions/38661/how-do-i-run-sh-scripts/38666#38666
https://www.cyberciti.biz/faq/run-execute-sh-shell-script/
open the location in terminal then type these commands
1. chmod +x filename.sh
2. ./filename.sh
that's it
I installed ender js and am running it from the command line. It generates a file called ender.js. Whenever I run the command "ender info" or anything with ender in it, it opens the ender.js file in notepad.
How can I stop the file from opening and get the command to run? It runs when I delete the file, but I need the file.
Windows runs it's own JS executor in the command line. This is in the PATHEXT system variable. This system variable stores an order for file extensions to be executed if there are files in the current directory that match. When I remove JS from that list, the command I am trying to call works. It does mean I won't be able to execute JS files in the browser now, but I have never needed to do that so far.
So uou are trying to run a javascript from the command line? that is what i infered here sorry if i am incorrect. That is done with the C:> cscript jslint.js command from the command line.
You can usually get around this by typing ender.cmd or ender.bat (depends how it is installed).
I decided to learn C++ (I program in C at work), and I have been reading some tutorials (and lots of posts here on Stack Overflow). OK, so I typed in the standard C++ "hello word", compiled with GCC on my Ubuntu machine as "test".
Then I tried to run it by typing "test" and hitting enter. Nothing. It turns out I must run it with "./test". OK, fine, I'll do that from now on. But why? The "./" just says that what I should run is in the current directory... Is the current directory not always part of the PATH when the OS is searching for something to run? Can I make it so?
Yes, the current directory is not part of your PATH. You don't want it to be, because then you could be in a directory that had a malicious program you didn't know about that you run.
What if you were used to running /usr/bin/grep, but you happened to be in a directory that a Bad Person put a malicious copy of grep in, and this time you run grep, and you're running grep out of the current directory, rather than /usr/bin/grep.
You certainly can add ./ to your PATH in your ~/.profile or ~/.bash_profile, but I don't recommend it.
And if it makes you feel any better, I had the same frustration 15 years ago when I started using Unix-like systems.
You can add "." to your PATH, but that won't help you in this case - "test" is a shell built in.
Unfortunately, there is a Unix command called "test"...
If there's a command line script you regularly run, you could set up a command line alias to rid yourself of the need to type ./ each time.
Even if the current directory is at the very beginning of the $PATH, 'test' still won't run it on (most?) shells, as 'test' is a shell built-in command.
Not having '.' (the current directory) in the PATH is a minor security measure. You could always add it in if you'd like, though it's not a best practice.
In case it's not clear, this is an aspect where Windows differs from Unix/Linux. On Windows, the current directory is implicitly in the path.