Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
anyone help what this command does as I do it with a single > and it creates a new file when I do ls > list, but I can see nothing when I do ls >> list
As already mentioned, > overwrites while >> appends.
Now for the query that you have,
You first executed ls > list, created a file named list.
Then, you executed ls >> list, which appended the result of ls command to your existing file. You can see the changes only if you open the file.
Try the following:
Remove the existing list file: rm -f list
Execute ls >> list, this will create the file list.
Execute ls > list, this will overwrite the contents of the file list.
Remember:
> and >> will both create the file if it does not exist.
Consequent executions of > on existing file will overwrite the file, while that of >> will append the output to the file.
In any case, you will be able to see the change only when you open the file after > or >> operation.
> is used to redirect the standard output to a file. (command > output file)
If file exist it will replace it. If you want to append, use >>instead.
So if you do ls > file, then file will content the files in your directory (id est output of the ls command)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
So I have an assignment in linux terminal asking me to create a file in the home directory and to make the file display all the commands of the bash shell which is found in the /bin directory.
I already tried to use the echo command to display the commands to the file but it is not working:
echo $ls /bin > File1
I expect that the file contains all the commands of the bash shell, but when I type the line above in the linux terminal, the content of the file is just the word "/bin".
Is there any other way to use to meet the expected result?
Here you don't need the echo command, as ls already prints to standard output, which can then be piped to the file. The command you want is:
ls /bin > File1
A good way to go about this is by checking that "ls /bin" by itself will print to standard output the contents of /bin, and once you see the expected output, run it again with the "> File1" to then output to File1.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
In linux server, is there a way to get the list of files in a directory
without using commands such as ls-la?
Our log directory size is too huge (almost 90GB) that
when we use ls -la command to get the list of files in that directory,
the command prompt does not come back...
echo *
... will show files in the current folder through file globbing on Bourne compatible shells.
This lists all files down one level:
echo /
In Bash, if globstar is set (set with shopt -s globstar, unset with shopt -u globstar), this will list all files recursively:
echo **
For More info, you may visit This Link
and your following problem why not you use a limit to list file?
this command may help you
ls -U | head -4
Don't know if there are other commands, but you could combine ls with other command like:
ls -la | less
which still lists your files but you can move up and down (and search) easily. less does not load all the content (your 90GB) at once but it loads lines when you move around.
Or you can save output of ls to a file to open it later
ls -la > my_files.txt
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
I want to rename all files in selected directory using rename command or move command from :
_02_mp3_cbr_320.m4a?anghakamitoken=sc245ae5a454547.5
_02_mp3_fsgsfsdfsfdfdsfcbr_320.m4a?anghakamitoken=sc245.ae5a
to
1.m4a
2.m4a
If those files always have a sheme like this:
_02_mp3_ * _320.m4a?anghakamitoken= *
You can do it like that:
#!/bin/bash
COUNT=0
for f in ./"_02_mp3_"*"_320.m4a?anghakamitoken="*; do
mv $f "$((++COUNT)).m4a"
done
This will result in
1.m4a
2.m4a
Assuming the initial files are in the same directory as the bash script.
Try this with GNU Parallel. it basically uses GNU Parallel's job number ({#}) as the number for renaming:
parallel --dry-run -k mv {} {#}.m4a ::: *m4a*
Sample Output
mv _02_mp3_cbr_320.m4a\?anghakamitoken\=sc245ae5a454547.5 1.m4a
mv _02_mp3_fsgsfsdfsfdfdsfcbr_320.m4a\?anghakamitoken\=sc245.ae5a 2.m4a
If the commands look correct, remove the --dry-run part and run it again. The -k keeps the output in order. The {} refers to the current file.
Make a backup before using any commands you are unfamiliar with...
To rename any file in Linux using mv (move) command:
mv (cfr. "man mv")
In this case, you need to enter the following lines on the command line:
$mv _02_mp3_cbr_320.m4a?anghakamitoken=sc245ae5a454547.5 1.m4a
$mv _02_mp3_fsgsfsdfsfdfdsfcbr_320.m4a?anghakamitoken=sc245.ae5a 1.m4a
It is important that you refer to the manual when you know the command you must use, to understand how to use it.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
As the title says what does -LA do in a ls command?
I tried reading the manual for ls and this what it said:
-A List all entries except for . and ... Always set for the super-user.
-L Follow all symbolic links to final target and list the file or directory the link references rather than the link itself. This option cancels the -P
option.
But I'm not quite sure what those mean.
the ls command prints a list of files and folders in the current directory.
When using ls -A, the command prints out ALL files and folders in the current directory. This includes hidden files and folders (like files/folders starting witch a dot). However, . (current directory) and .. (parent directory) will be ignored.
When using ls -L the command will follow symbolic links and print out the location of the reference too.
When combining this 2 options you get ls -LA which prints out a list of ALL files and folders, and also prints out the references to symbolic links in the folder.
Just try it out in the terminal. You'll see the difference.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
When I am using the cut command in linux, and redirecting the output to the same file, it seems to delete the contents of my file. What I am doing is:
cut -d " " -f 1 file1.txt > file1.txt
My goal is to cut out all columns from the file, except for the first column and save changes to the file that I am working with. But when I do this, and open my file, I am left with a blank file. However, when I specify a different file, the command seems to work perfectly fine.
When I run:
cut {some command} FILE1.txt > FILE2.txt
This seems to work fine.
Is there a way that I can specify that I want the changes from my cut command to be overwritten on to my current working file?
Create a temporary file with the desired changes and then rename it to the target file name:
cut -d " " -f 1 file1.txt > file1.txt.temp
mv file1.txt.temp file1.txt