date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,353,826,112,000 |
I run this command to find the biggest files:
du -Sh | sort -rh | head -5
Then I do -rm rf someFile.
Is there a way to automatically delete the files found from the former command?
|
If you're using GNU tools (which are standard on linux), you could do something like this:
stat --printf '%s\t%n\0' ./* |
sort -z -rn |
head -z -n 5 |
cut -z -f 2- |
xargs -0 -r echo rm -f --
(remove the 'echo' once you've tested it).
The stat command prints out the filesize and name of each file in the c... | Find biggest files and delete automatically |
1,353,826,112,000 |
I have a directory full of logs named in the following style:
info.log00001
info.log00002
info.log00003
...
info.log09999
info.log
My current output (using grep -c)
I need to analyze the frequency a particular error that happens occasionally, so go to that directory and use grep -crw . -e "FooException BarError" |... |
If you have gnu find - and assuming none of your file names contains newlines - you could use find's -printf to output the mtime in the desired format + the file name then run grep to get the count:
find . -type f -printf '%TY-%Tm-%Td %TH:%TM %p: ' -exec grep -cw "whatever" {} \; | sort -k1,1 -k2,2
Alternatively, wi... | Add mtime to grep -c output and sort the output by mtime |
1,353,826,112,000 |
Sometimes it happens that I have a list of files or strings in the clipboard and want to paste it as an argument list in a bash shell:
Example file list (only an example):
createsnapshot.sh
directorylisting.sh
fetchfile.sh
What I want:
md5sum createsnapshot.sh directorylisting.sh fetchfile.sh
Currently, I enter the ... |
If the commands don't use stdin, use xargs, which reads input and translates it to arguments (note that I am using the echo command to show how xargs builds the command):
$ xargs echo md5sum
# paste text
createsnapshot.sh
directorylisting.sh
fetchfile.sh
# press Ctrl-D to signify end of input
md5sum createsnapshot.sh ... | Interactively add arguments line-by-line in bash |
1,353,826,112,000 |
I recently created a username and a group called gamesForAdmin. Since then I deleted it and the folder I made for it is still there:
drwxr-xr-x 5 root root 4096 Jul 4 11:28 .
drwxr-xr-x 23 root root 4096 May 29 12:41 ..
drwxr-xr-x 2 sftpuser sftpaccess 4096 Jul 4 11:24 gamesForAdmin
drwxr-xr-x ... |
Based on the output you're showing in your question the directory gamesForAdmin is not empty, so rmdir cannot remove this directory. To remove it you'll need to use rm -fr instead. Try this:
sudo rm -rf gamesForAdmin
which should fix you right up.
| Removing a directory that has no files in it |
1,353,826,112,000 |
I am trying to get ls like output from find command (this is on Linux Mind with find (GNU findutils) 4.7.0.
This is because I want to see the numerical chmod permissions.
What I managed so far is:
% find . -maxdepth 1 -printf "%m %M %y %g %G %u %U %f %l\n"
755 drwxr-xr-x d blueray 1000 blueray 1000 .
664 -rw-rw-r-- f... |
You can tell find to print one thing for links and another for non links. For example:
$ find . -maxdepth 1 \( -not -type l -printf "%m %M %y %g %G %u %U %f\n" \) -or \( -type l -printf "%m %M %y %g %G %u %U %f -> %l\n" \)
755 drwxr-xr-x d terdon 1000 terdon 1000 .
644 -rw-r--r-- f terdon 1000 terdon 1000 file1
755 ... | How to get ls like output using find command |
1,353,826,112,000 |
Let's say if my text file contains:
101 Adam
201 Clarie
502 Adam
403 Tom
and i want to write a command in the shell to only give me the numbers based of a specific name. For example, only output the number for the name 'Adam' would give:
101
502
I was thinking of something like:
cut -f 1 Data_1 | grep "A... |
First you have the order of grep/cut backwards. And, unless those are actual tabs (as in Tab) separating your columns (I can't tell) you also need to specify that normal whitespace (as in Space) is your delimeter.
grep Adam Data_1 | cut -f1 -d' '
If you are using tabs then leave off -d' '.
Generally speaking try one ... | Getting only specific data based on name in text file |
1,353,826,112,000 |
Sometimes I find myself installing a package and then trying to run a command using the same name, like with geoip-bin package:
$ sudo apt install geoip-bin
[...]
$ geoip-bin
geoip-bin: command not found
How may I find all the commands associated with a given package?
|
dpkg -L
-L, --listfiles package-name List files installed to your system from package-name.
Two alternatives:
Usually works just: dpkg -L byobu | egrep '/bin/|/sbin/' (or even with grep bin if you don't care getting some false positives).
Or
dpkg -L byobu | xargs which
Or with some bash magic:
for f in $(dpkg -L geo... | How to find commands associated to a package? [duplicate] |
1,353,826,112,000 |
I have come to learn that it is compulsory to learn C language before trying to learn Linux.
What is the reason behind it?Does the knowledge of C somehow aid me in understanding Linux commands,file directories better?
And yes,if I must learn C how do I know when that I have learnt enough to begin Linux.
Thank you
|
Linux is just an operating system kernel. A core component found at the heart of some operating systems like Android, ChromeOS, Ubuntu or Fedora.
You don't use Linux, you use software built for Linux.
For instance, a command line is something that is interpreted by another piece of software called a shell. Such shells... | Why learn C at all? [closed] |
1,353,826,112,000 |
I have a folder with a complicated folder structure:
├── folder1
│ ├── 0001.jpg
│ └── 0002.jpg
├── folder2
│ ├── 0001.jpg
│ └── 0002.jpg
├── folder3
│ └── folder4
│ ├── 0001.jpg
│ └── 0002.jpg
└── folder5
└── folder6
└── folder7
├── 0001.jpg
└─... |
I have no idea why the first solution in your question wouldn't work. I can only assume you forgot to remove the echo. Be that as it may, here's another approach that should also do what you need, assuming you're running bash:
shopt -s globstar
for i in **/*jpg; do mv "$i" "${i//\//_}"; done
Explanation
The shopt -s... | Flattening complex folder structures with duplicate file names |
1,353,826,112,000 |
The formatting character %s makes stat print the filesize in bytes
# stat -c'%A %h %U %G %s %n' /bin/foo
-rw-r--r-- 1 root root 45112 /bin/foo
ls can be configured to print the byte size number with "thousand-separator", i.e. 45,112 instead of the usual 45112.
# BLOCK_SIZE="'1" ls -lA
-rw-r--r-- 1 root root 45,112 ... |
Specify the date format, but leave it empty eg.
ls -lh --time-style="+"
Produces
-rwxrwxr-x 1 christian christian 8.5K a.out
drwxrwxr-x 2 christian christian 4.0K sock
-rw-rw-r-- 1 christian christian 183 t2.c
| change file size format when using stat |
1,353,826,112,000 |
I am getting output from a terminal in Ubuntu 12 that I don't understand.
$cat sublime
no such file or directory
$mkdir sublime
cannot create directory 'sublime': File exists
How can both of these be true? I am trying to install sublime text with these instructions but having trouble making a symbolic link because /... |
A "file" can be a couple of things. For example man find lists:
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link
... | Can't cat a file or make a directory: contradictory output? |
1,353,826,112,000 |
I need to run these commands very often:
sudo apt-get install <package>
sudo apt-get remove <package>
Can I make it simple like:
install <package>
remove <package>
I think I need to write a function like this:
function install(){
sudo apt-get install <package>
}
...and then need to copy paste to some location i do... |
Use shell aliases, they won't interfere with other scripts/commands, they are only replaced when the command has been typed interactively:
alias install="sudo apt-get install"
You may place this in your shell configuration file (~/.bashrc for example) and it will be defined in all your shell sessions.
| creating simple command for sudo apt-get install? |
1,353,826,112,000 |
I've got a bunch on strings which I need to find in a couple of files, for example:
string1
string2
stringn
file1.txt
file2.txt
filen.txt
Is there an (easy) way to do that in bash? I need to know, if a string was found, in which file is it.
|
Simple grep command with -e option:
grep -e "string1" -e "string2" -e "stringn" file*.txt
Or you can put all the search strings in a file called search.txt like this:
string1
string2
string3
...
...
stringN
and then run grep like this with -f option:
grep -f search.txt file*.txt
| Searching strings on files |
1,353,826,112,000 |
I have a sed oneliner, to print line range from a file:
sed -n '10,20p' file.txt
The above will print lines 10 to 20 from file.txt.
But how can I also print the line numbers?
|
Only using sed.
sed -n '10,20{=;p}' file.txt | sed '{N; s/\n/ /}'
N; tells sed to add the next line into the pattern space, so now sed is working with both lines.
s/\n/ / replaces the newline character with a space, "merging" the two lines together.
Sources :
(1) Numbering lines matching the pattern using sed
(2) ... | Print line range from file, and include line numbers |
1,353,826,112,000 |
I am following this question though some of the file names here contain a dash at the beginning of the filename. This is interpreted as an additional option for cp.
Following another question (on ServerFault), I tried altering the command to:
shuf -zn8 -e *.jpg | xargs -0 cp -vt -- {} target/
or
shuf -zn8 -e *.jp... |
The -t option (a GNU extension) takes an argument which is the target directory.
With xargs -0 cp -vt -- target/, that would try to copy target/ and the selected files into a directory called --, and you would still not have marked the end of options. You would need to mark the end of options for shuf as well.
{} is o... | Coping with filenames starting with a dash ("-") when using `-exec` and `xargs` |
1,353,826,112,000 |
There are a couple of questions related to the fork bomb for bash :(){ :|: & };: , but when I checked the answers I still could not figure out what the exactly the part of the bomb is doing when the one function pipes into the next, basically this part: :|: .
I understand so far, that the pipe symbol connects two com... |
Short answer: nothing.
If a process takes in nothing on STDIN, you can still pipe to it. Simiarly, you can still pipe from a process that produces nothing on STDOUT. Effectively, you're simply piping a single EOF indicator in to the second process, that is simply ignored. The construction using the pipe is simply a va... | What exactly is the function piping into the other function in this fork bomb :(){ :|: & };:? |
1,353,826,112,000 |
I was following a tutorial on how to find out the dependent libraries of a program and it was explained like this:
whereis firefox
shows the folders, where it is installed, take the full path to the binary, and
ldd /usr/bin/firefox put it as argument of the ldd command.
the tutorial also used firefox as an example ... |
The firefox executable is a shell script on your system.
Some applications employ a wrapper script that sets up the execution environment for the application, possibly to allow for better integration with the current flavor of Unix, or to provide alternative ways to run the application (new sets of command line option... | Why does not "ldd /usr/bin/firefox" list library files? |
1,353,826,112,000 |
I tried the following :
[$] wget http://cdn.edgecast.steamstatic.com/steam/apps/256679148/movie480.webm > Conan1.webm
[1:21:05]
--2017-02-23 01:51:50-- http://cdn.edgecast.steamstatic.com/steam/apps/256679148/movie480.webm
Resolving cdn.edgecast.steamstatic.com (cd... |
You didn't "suggest it took" the name Conan1.webm, you redirected its standard output stream to file called Conan1.webm. Since wget doesn't write to standard output by default, that has no effect on where the content is saved.
See man wget - in particular the -O option:
-O file
--output-document=file
The documents... | Why doesn't wget url/mediafile.ext > medafile2.ext work? |
1,481,873,711,000 |
Sometimes when I log on to a system via SSH (for example to the production server), I have such privileges that there can install some software, but to do that I need to know the system with which I am dealing.
I would be able to check how the system is installed there.
Is there a way from the CLI to determine what d... |
Try:
uname -a
It will give you output such as:
Linux debianhost 3.16.0-4-686-pae #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) i686 GNU/Linux
You can also use:
cat /etc/*release*
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.... | How can I get system information from the command line? [duplicate] |
1,481,873,711,000 |
I have a multi columns csv file, comma separated which has two columns with different date (mm/dd/yyyy). I am going to identify the difference between these two date. following is the example:
echo filename
001xxxc,28.2,03/04/2009,11/19/2009
00cvbfd,34.4,03/04/2009,01/06/2010
04rsdsd,34,12/01/2006,10/02/2... |
Assuming you want the difference in days, then if you have GNU awk (gawk) you could do something like
gawk -F, '
{
split($3,a,"/");
split($4,b,"/");
t1 = mktime(sprintf("%d %d %d 0 0 0 0",a[3],a[1],a[2]));
t2 = mktime(sprintf("%d %d %d 0 0 0 0",b[3],b[1],b[2]));
print (t2-t1)/86400
}
' file... | How to use awk command to calculate the date difference between two columns in the same file? |
1,481,873,711,000 |
I'm trying to do this but I cant create the file.
I enter: sort myfile.txt uniq -u | tee newfile.txt
and It wont create the file automatically. What am I missing here?
|
You are missing one pipe | character.
Try: sort myfile |uniq -u|tee newfile.txt
If this is not working, please provide the error message you are getting.
By the way, this command uniq -u eliminates all lines which have duplicates. If this is your intention, that is fine. But if you want to see one of the duplicate lin... | Give the command to remove duplicate lines in a .txt file and save the new file as new.txt file |
1,481,873,711,000 |
EDIT: Total rewrite of question for clarity.
I have a directory tree (new) with a bunch of files of with an extension of .new. I have an identical tree (old) where many of the files have names identical to those in the new tree except that the extension is .old. I would like to copy all of the .new files from the new... |
This was the final answer that got hashed out in the comments for terdons answer.
cd new
for i in */*/*.new; do cp "$i" "path/to/old/${i}" && rm "path/to/old/${i//new/old}"; done
| Need to copy files to existing directory and remove files already there with the same name but different extension |
1,481,873,711,000 |
What is the correct format for if then?
I tried lots of varieties.
Should the format work at the command line when not in a program?
$ if [1==2] then echo "y" fi;
> ;
-bash: syntax error near unexpected token `;'
|
Try this one:
if [ 1 == 2 ]; then echo "y" ; fi
And better use -eq, unless you want to compare 1 and 2 as a strings.
Useful link: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
| -bash: syntax error near unexpected token `;' [duplicate] |
1,481,873,711,000 |
I need to find my OS (not hardware) is 32-bit / 64-bit. Which command is best?
uname -p
uname -i
uname -m
arch
All the above commands returns the same answer:
On 32 bit systems: i686/i386
On 64 bit systems: x86_64
|
I would recommend instead using getconf LONG_BIT.
[root@mymachine ~]# getconf LONG_BIT
64
This will clearly output either 32 or 64, depending on your installed kernel, whereas uname -m (and etc.) indicate the underlying hardware name.
See also the Stack Overflow question How to determine whether a given Linux is 32 b... | Which cmd is the best for determining the OS' word size (32/64)-bit? [duplicate] |
1,481,873,711,000 |
I don't quite understand pipes in Linux command line.
I noticed that:
ll - R | grep *.pdf
will list files ending with .pdf
But
locate *.pdf | du -h
will not calculate the size of files ending with .pdf. Rather it will list the size of files in the current directory.
What is going wrong here?
What I have in mind i... |
Pipes work by sending one program's output to another program's input. This means that the program receiving the output of the other has to be able to read from STDIN (standard streams).
In this case, grep is able to read the output of ll because it is designed that way. du expects a command line argument pointing to... | Passing values through pipes |
1,481,873,711,000 |
I have data like:
['/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/', '/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/cus... |
You could just remove the leading [', trailing '] and replace all ', ' with a newline, and delete a [] or @as [] line which I see gsettings using to represent empty lists of strings (where the @as prefix specifies that the array is an array of strings).
gsettings get some-path some-array-key... |
sed "/^@as \[\]\$/d... | Extract data which is inside square brackets and separated by comma |
1,481,873,711,000 |
I would like to list the files matching a specific pattern along with their number of rows.
So far I have tried the following, which list me the files matching the desired pattern:
find 2021.12.*/ -maxdepth 2 -name "myfilepattern.csv" -ls
123456789 32116 -rw-rw-r-- 1 user1 user1 32881884 Dec 1 23:59 2021.12.01/m... |
You can use -printf and -exec actions, along with wc -l to count lines/rows:
find 2021.12.*/ -maxdepth 2 -name "myfilepattern.csv" -printf '%i\t%k\t%M\t%n\t%u\t%g\t%s\t%Tb %Td %TH:%TM\t' -exec wc -l {} \;
The row count will be the second to last column.
| Count number of rows of files matching pattern [closed] |
1,481,873,711,000 |
For now i use this:
mkdir -p a/b/c/d/e;
touch a/b/c/d/e/file.abc;
Is there more efficient ways?
|
In terms of tools used: no.
touch will fail (rightly) if you are trying to operate in a directory that does not exist, and mkdir does precisely one thing: create directories, not normal files.
Two different jobs mandate two different tools.
That said, if you're talking about efficiency in terms of the number of lines ... | Create file in subdirectories that doesn't exist (../new_folder/new_folder/new_file.ext) |
1,481,873,711,000 |
Is it possible to change the default behavior of a command?
I assume that this question is pretty straight forward but let me give an illustration and example.
While connected to some servers via SSH autocomplete via tab does not work making long commands long tedious. For example here is a ls command:
ls -lah --grou... |
The typical way of doing this on Unix- or Linux-style systems is to use shell aliases:
alias ls='ls -lah --group-directories-first'
Note that this will overwrite any existing ls alias, so you might want to check the output of
alias ls
first and combine the above; for example
alias ls='ls -lah --group-directories-fir... | Is it possible to change the default behavior of a command? |
1,481,873,711,000 |
I have some .jpeg images saved in a file in a cluster at school. I am at home using PuTTY to access one of the Debian nodes. I'm able to get to the folder with all the images but I need to see the dimensions of each one in order to run one more computation on them. Is there a way to do this?
In keeping with one of the... |
There are number of tools that will do this:
identify from ImageMagick
jhead
jpeginfo
some versions of the file command
If these programs are not installed, note that both jhead and jpeginfo are quite simple and presuming a compiler is available will be easy to build in your own user account.
| Is there a way to see the dimensions of a jpeg file in linux using the command line? |
1,481,873,711,000 |
I read the following in the grymoire:
A simple example is changing "day" in the "old" file to "night" in the "new" file:
sed s/day/night/ <old >new
Or another way (for UNIX beginners),
sed s/day/night/ old >new
Why might the author consider the first form more advanced?
I mean, what are the advantages of... |
One advantage to allowing the shell to do the open() like:
utility <in >out
as opposed to allowing the named utility to do the open() like:
utility in >out
...is that the file-descriptor is secured before the named utility is called, or else if there is an error encountered during the open(), the utility is never ca... | Input from file: "advanced" (using less-than sign) vs. "beginner" syntax |
1,481,873,711,000 |
Ran across a shell script that had '=~' in a contitional and I was wondering what it meant. Not much luck on Google or SO sites.
Example:
if [[ $VAR =~ 'this string' ]]
|
It's a regular expression match operator.
From the bash man page:
An additional binary operator, =~, is available, with the same
precedence as == and !=. When it is used, the string to the
right of the operator is considered an extended regular
expression and matched accordingly (as in regex(3)). The return
value is... | What does =~ mean? [duplicate] |
1,481,873,711,000 |
I'm trying to use apropos so that I would look for all man pages starting with system.
I try:
apropos ^system
apropos "^system"
but these seem to return lines that don't start with system, but where system occurs somewhere in the line.
Any ideas?
Edit
As per comment below, the above actually works but it matches ag... |
Running apropos '^system' works for me, returning the list of man pages where either the page name itself starts with system or the one line description starts with system.
For example, the output on Debian (jessie) includes:
system-config-printer (1) - configure a CUPS server
sigset (3) - System V signal API
I know ... | apropos regex start with? |
1,481,873,711,000 |
I've got some third party log files I'm trying to pull errors out of on the command line.
The logs look like this:
time=1
time=2
time=3
at com.test.com....
at com.test.com....
at com.test2.com....
time=4
time=5
time=6
time=7
time=8
time=9
at org.badstuff.com...
at org.badstuff.com...
at org.badstuff.com..... |
Just use -After context, -Before context or -Context option in grep, e.g. to fit to your example:
grep -B2 '^\t' file
| How to match multiple lines starting with a TAB, and the line before the 1st one in a group? |
1,481,873,711,000 |
I am trying to list all of the files that include a function, e.g., matrixCal.
How can I to do this in linux?
|
Would grep be ok?
grep -R matrixCal /location/of/your/code
| How to find every file that includes a given function? |
1,481,873,711,000 |
I have this command:
sed -i 's/^CREATE DATABASE.*$//' world.sql
If I run that, it says:
sed: -I or -i may not be used with stdin
and creates a new file called orld.sql. The original file still exists afterwards.
So I guess, sed sees world.sql as a w orld.sql command?
How can I prevent that behaviour?
[This is on ma... |
As far as I know, sed on MacOS is the FreeBSD flavor which requires a backup suffix to be supplied when using the -i option. The error message you get implies that it mis-interpreted parts of your command because you used the option without providing one.
So, try it with
sed -i".backup" 's/^CREATE DATABASE.*$//' world... | Using "sed" with "-i" option creates strangely-named new file while leaving the input file untouched |
1,481,873,711,000 |
I am trying to find a command that displays files larger than 1 GB and displays those files ordered by size. I have tried find . -maxdepth 2 -type f -size +1G -print0 |xargs -0 du -h |sort -rh but for some reason this displays files of size that are not greater than 1 GB.
For example this is in the output 1.0K ./<r... |
There are at least two possible causes:
Maybe your find prints nothing. In this case xargs runs du -h which is equivalent to du -h .. Investigate --no-run-if-empty option of GNU xargs. Or better get used to find … -exec … instead of find … | xargs …. Like this:
find . -maxdepth 2 -type f -size +1G -exec du -h {} + | ... | Linux show files in directory larger than 1 GB and show size |
1,481,873,711,000 |
I have the following basic.json file:
{
"user": "user",
"pass": "password"
}
I'm trying to encode it in base64 like this:
"Basic dXNlcjpwYXNzd29yZA=="
I think I'm close:
echo Basic $(echo $(cat basic.json | jq '.user'):$(cat basic.json | jq '.pass') | base64)
I've used the jq access method found here.
I've ... |
Using jq and @base64 operator:
<basic.json jq '"Basic " + ("\(.user):\(.pass)"|@base64)'
"Basic dXNlcjpwYXNzd29yZA=="
user and pass values are given as string to base64 operator. The rest is simple string concatenation.
| How to properly encode string based on json file? |
1,481,873,711,000 |
my file pheno_Mt.txt looks like this:
IID pheno
1000017 -9
1000025 -9
1000038 1
1000042 -9
1000056 -9
So it is space separated and I would like to convert it into tab separated.
I tried:
cat pheno_Mt.txt | tr ' ' '\t' > pheno_Mtt.txt
and this:
sed 's/ /\t/g' pheno_Mt.txt > pheno_Mtt.txt
but this just tab separated... |
$ tr ' ' '\t' <pheno_Mt.txt
IID pheno
1000017 -9
1000025 -9
1000038 1
1000042 -9
1000056 -9
This looks as if the tr command only did something to the first line of the file, but since the output of a tab brings the cursor up to the next multiple of eight position on the screen, and since this happens to be exactl... | How to convert space separated file into tab separated? [closed] |
1,481,873,711,000 |
function mv1 { mv -n "$1" "targetdir" -v |wc -l ;}
mv1 *.png
It does only move the first .png file it finds, not all of them.
How can I make the command apply to all files that match the wildcards?
|
mv1 *.png first expands the wildcard pattern *.png into the list of matching file names, then passes that list of file names to the function.
Then, inside the function $1 means: take the first argument to the function, split it where it contains whitespace, and replace any of the whitespace-separated parts that contai... | Why does a file move/copy function only move one file at a time when using the “*” wildcard? |
1,481,873,711,000 |
My system:
OS: MacOS / Mac OS X (Mojave 10.14.5)
OS core: Darwin (18.6.0)
Kernel: Darwin Kernel / XNU (18.6.0 / xnu-4903.261.4~2/RELEASE_X86_64)
ls: version unknown, but man ls gives a page from the BSD General Commands Manual
Shells:
Bash: GNU bash, version 5.0.7(1)-release (x86_64-apple-darwin18.5.0)
Zsh: zsh 5.7... |
You could execute ls in a subshell:
(cd arg; ls -d *[^~])
| On a Mac, how can I list contents of a non-current directory without showing backup files (ending with ~), preferably with BSD command ls? |
1,481,873,711,000 |
On Mac, the reset command in terminal almost does the same thing as clear. On Ubuntu Linux, and maybe other flavors of Linux, the reset command actually "resets" the terminal so that you can't scroll up or see previously input commands by scrolling. Is there a way to make the reset command on Mac act/do the same thing... |
Actually (on MacOS), it's not "the exact same thing" (the manual page description for "clear" is different from "reset").
MacOS comes with ncurses 5.7 (9 years old), with some updates to the terminal database. If you want something newer, installing MacPorts lets you update ncurses to the current (less a few months) ... | Make reset on Mac like reset on Linux |
1,481,873,711,000 |
Think of it as going to the most high level folder, doing a Ctrl Find, and searching .DS_Store and deleting them all.
I want them all deleted, from all subfolders and subfolders subfolders and so on. Basically inside the top level folder, there should be no .DS_Store file anywhere, not even in any of its subfolders.
W... |
find top-folder -type f -name '.DS_Store' -exec rm -f {} +
or, more simply,
find top-folder -type f -name '.DS_Store' -delete
where top-folder is the path to the top folder you'd like to look under.
To print out the paths of the found files before they get deleted:
find top-folder -type f -name '.DS_Store' -print -e... | How to remove all occurrences of .DS_Store in a folder |
1,481,873,711,000 |
From the Bash manual, Section 6.6 Aliases,
…
Bash always reads at least one complete line of input before
executing any of the commands on that line.
Aliases are expanded when a command is read, not when it is
executed. Therefore, an alias definition appearing on the same line as another command does not... |
The part of the Bash manual you quoted talks about
Aliases are expanded when a command is read, not when it is executed. Therefore, an alias definition appearing on the same line as another command does not take effect until the next line of input is read.
So aliases are actually one of those examples that show the... | How can I show the results after Bash reads one complete line of input but before executing any of the commands on that line? |
1,481,873,711,000 |
I have removed all my python code from the home directory, but when I do ls I get:
a11.py~ class1.pdf foobar.txt~ n1 pic.py~
When I do ls like this: ls *.py I get:
ls: cannot access *.py: No such file or directory
I still have lot of files like the above. Are they hidden files or what?
How do I solve this?
|
The ~ is part of the filename:
ls *.py~
Thus, to delete all such files:
rm *~
| How to delete files with ~? |
1,481,873,711,000 |
I noticed that some commands also come in with e- and f- versions, e.g. grep, egrep, fgrep and a few others.
Is there some pattern or a naming convention if a particular command should have e- or f-version?
|
There is a clue about this in, e.g., man grep, which is also man fgrep and man egrep -- very often tools with minor variations like this will have one man page for all the variations, explaining them in relation to one another:
In addition, two variant programs egrep and fgrep are available.
egrep is the same as g... | e- and f- versions of commands |
1,481,873,711,000 |
I don't remember exactly but there was either cp or mv command which I was able to do something like this with:
cp file{.cpp, .cpp.org}
Which would copy file.cpp and make a copy named file.cpp.org. Any suggestions?
|
This is a property of the shell, and not a property of the command itself. Check for more info: http://wiki.bash-hackers.org/syntax/expansion/brace
On the command line,
file{.cpp,.cpp.org}
will always expand to
file.cpp file.cpp.org
In your example, it would be shorter to just type
file.cpp{,.org}
| cp : short way of copying [closed] |
1,481,873,711,000 |
Using pdftk it is possible to extract page ranges from a pdf using
pdftk a.pdf cat 124-end output b.pdf dont_ask
I have a bunch of huge PDFs with about 500 pages and over 100 MB, is it possible to automatically split those in pieces of maximal 5 MB?
|
I found this python script called smpdf that has this feature. This script is written in German (some of it) but it's easy enough to figure out what it's doing and how to use it. It requires PyPdf.
Installation & Setup
First download the script:
svn checkout http://smpdf.googlecode.com/svn/trunk/ smpdf
Then download ... | Splitting large PDF into small files |
1,481,873,711,000 |
I am using CentOS 5.6, is there a way to view a "live" time, without constantly executing the date command?
Constantly excuting the date command can be quite frustrating and repetitive when checking the time for running cron jobs.
|
If you want to periodically execute a specific command you can use watch (1). Per default the specified program is executed every two seconnds.
To run date every second just run:
watch -n 1 date
| CentOS 5.6 live time feature without repeatedly executing date command |
1,481,873,711,000 |
I'm new to Unix/Linux platforms so I was hunting for good books on *nix... I soon realized there is not one book or resource. But to gain confidence on the command line and scripting (the real *nix user) I finally found two books:
1.The Linux Command Line
2.Linux Command Line and Shell Scripting Bible
Both seem to be... |
I have a general rule of thumb when buying any tech book, avoid the ones that weigh more than a phonebook (remember those? ;)). Avoid any book for dummies, unless you think you are a dummy, avoid any listed as a "Bible".
The big fat books are a marketing ploy with tons of white space, large font, and excessive example... | Stuck between these two books? [closed] |
1,481,873,711,000 |
For djvused command, there is an option:
-e command
Cause djvused to execute the commands specified by the option argument
commands. It is advisable to surround the djvused commands by single
quotes in order to prevent unwanted shell expansion.
For example, djvused myfile.djvu -e 'print-pure-txt'.
It is quite un... |
It is quite usual, some programs base their working exclusively on this.
Some of the more common examples that come to mind are su, sudo and xterm.
su -c 'ls -l /root'
sudo ls -l root
xterm -e 'top -d 10'
It is different from your example
echo `echo hello`
where the inverse quotes are interpreted by the shell, and ... | A command used in another command |
1,308,650,780,000 |
I need Gzip to pre-zip some static files for a webserver I'm building. All of the files I need to gzip will be in a folder named .cache. Since some clients may not accept responses that are gzipped, I would like to keep all of the original files when I gzip them. Is there any command I can use to recursively gzip the ... |
Use the option -c to output the result to stdout. gziping all files in .cache:
for i in .cache/*; do gzip -c "$i" > "$i.gz"; done
EDIT:
To gzip them again and not gzip the gziped files check the suffix:
for i in .cache/*; do [ "${i:(-3)}" == ".gz" ] || gzip -c "$i" > "$i.gz"; done
So only files that not end in .gz w... | Recursively Gziping Files (and keep original files) & Gziping Text Input |
1,308,650,780,000 |
I want to manipulate a text-file. It contains many blocks of the form
CLASS
...some stuff ...
END
I want to duplicate each of these blocks and add and remove a line of it's content. Can I script that?
|
The natural tools for this are awk and Perl (assuming you want to script: for a once-off, the natural tool is an interactive editor). Here's an awk script that duplicates all CLASS…END blocks (no balancing supported: each CLASS matches the next END), except that foo lines are omitted from the second copy.
awk '
/^CL... | How can I manipulate the content of a file, by duplicating and changing some parts? |
1,308,650,780,000 |
I have files with the following format: File name is file.txt
chr - seq1 NZ_JAHWGH010000010.1 0 60562 green_a4
chr - seq3 NZ_JAHWGH010000012.1 0 466573 green_a4
chr - seq5 NZ_JAHWGH010000013.1 0 125526 green_a4
chr - seq6 NZ_JAHWGH010000014.1 0 717625 green_a4
chr - seq7 NZ_JAHWGH010000015.1 0 209757 green_a4
chr - se... |
You first awk attempt:
awk 'BEGIN{FS=OFS=" "}($4 == /^NZ_JAHWGH/){$3==seq1}1' file.txt
fails because $3==seq1 is a test of whether $3 is exactly equal to the value of the variable seq1. What you wanted is = instead of == so you are setting the value, not testing it, and "seq1" to indicate that this is a string and no... | Renaming column based on matching of second column in a text file |
1,308,650,780,000 |
Assume I have a directory with 5,000 files. each with a name such as:
1.json
2.json
3.json
..
4000.json
4001.json
what command-line utility can I use to grep for a string from only the files 1.json through 2000.json?
|
Bash, Ksh, Zsh:
grep pattern {1..2000}.json
Were the file names zero-padded:
grep pattern {0001..2000}.json
| How to grep from file names with number in range |
1,308,650,780,000 |
I know that sudo commandX asks for the user's password and if it is valid it executes commandX as root, until here all is ok. It is mandatory for some commands, such as apt, chown, chmod etc. It has sense for security reasons.
Now consider the following scenario/situation:
sudo commandA
... sometime
sudo commandB
Bec... |
You can get case 3 by doing sudo -n true 2>/dev/null -- if it has nonzero status the cached authentication has expired (or been removed).
| sudo: What command(s) use to know its timeout, time remaining and if the timeout expired? |
1,308,650,780,000 |
I installed Debian for CLI purposes.
How I can delete things related to the GUI without the system crashing (Because I do not need GUI packages to free up memory)?
|
This should delete most GUI applications and libraries:
sudo apt purge --auto-remove libx11-6 libwayland-client0
How I can delete things related to the GUI without the system crashing
Linux (distros) will not crash without the GUI. The only two things required for Linux to run are the kernel and the init process. T... | Debian - How I can delete things related to the GUI? |
1,308,650,780,000 |
I got into a situation that I need to rename lots of files in the form of:
file.csv
file_1.csv
file_2.csv
file_3.csv
file_4.csv
file_5.csv
file_6.csv
file_7.csv
file_8.csv
To better order, i.e.:
file_1.csv
file_2.csv
file_3.csv
file_4.csv
file_5.csv
file_6.csv
file_7.csv
file_8.csv
file_9.csv
I.e., I can manually re... |
You need to use perl's /e regex modifier to cause it to evaluate the right-hand-side of the s/// operation as a perl expression.
You also need to sort the filenames in reverse numerical order so that the highest-numbered filenames are renamed before the lower-numbered filenames (otherwise there will be filename collis... | Re-number and rename |
1,308,650,780,000 |
I'd like to be able to see if, for example, show-all-if-unmodified is enabled in the current session.
|
You seem to be looking for bind -V:
$ bind -V | grep show-all-if-unmodified
show-all-if-unmodified is set to `off'
As far as I can see, no variable name includes the whole name of a different variable (e.g. there is no show-all variable that will also match show-all-if-unmodified when used as a non-anchored pattern),... | How to list readline variables with their current value |
1,308,650,780,000 |
I would like to use the command line to put text in the GUI clipboard so that it can, for example, be pasted into a graphical web browser's text input field. I am using Kubuntu 20.04.
I tried as an example uptime | xclip, and when I press the middle mouse button, the uptime output is pasted. However, when I press Ctr... |
There are two sets of commands that can do this, xclip and xsel, and they can be used interchangeably. In order to use the clipboard used by graphical applications (rather than the terminal selection buffer), an option must be specified.
To copy into the clipboard:
uptime | xclip -selection clipboard
# or
uptime | xcl... | How to copy into graphical clipboard on command line in KDE? [duplicate] |
1,308,650,780,000 |
I would like to convert a float to a ratio or fraction.
Do we have the option to convert a float 1.778 to ratio as 16:9 or 16/9 in bash, in a fashion similar to Python's fractions module (Fraction(1.778).limit_denominator(100)).
|
Pedantic or not, if our man is looking only looking at 3 decimals of precision....
Breaking out the good old awk hammer for the equally good old fashioned lowest denominator, rather than the high falutin' algorithm, just find the lowest error and denominator
echo "1.778" | awk 'BEGIN{en=1; de=101; er=1}{
for (d=10... | How can I convert a float to ratio? |
1,308,650,780,000 |
I have a bash script runs a command in an infinite while loop. The script looks something like:
while :
do
python3 my_program.py
done
Is there a simple way to terminate this while loop from the terminal in a way that doesn't interrupt the python process? ie the python process will finish, then the loop terminate... |
You can trap SIGINT in your script and set a loop exit condition. Running your program with setsid prevents it from receiving SIGINT from CTRL+C
#! /bin/bash
STOPFILE=/tmp/stop_my_program
rm -f $STOPFILE
trap "touch $STOPFILE" INT
while [ ! -f $STOPFILE ]
do
setsid python3 my_program.py
done
rm -f $STOPFILE
... | Kill script, but allow currently executing program to exit |
1,308,650,780,000 |
I have to use
usermod -G groupname username
everytime to add user to group.
Isn't there any way to do it by single line like
usermod -G groupname user1,user2,user3
|
You can set the member list of a group with one command:
gpasswd -M user1,user2,user3,... groupname
But to add using this, you'll need to get the existing list:
gpasswd -M "$(getent group groupname | awk -F: '$4 {print $4","}')"user1,user2,user3,... groupname
But it's just easier to use xargs or loops manually:
for ... | How can we add multiple users to a group by single command in Linux? |
1,308,650,780,000 |
How do I find all folders containing a . in the foldename? I've tried the following, but it listed all folders, not what I wanted;
find . -maxdepth 2 -type d -ipath "."
I seem to have a lot of folders named somethign like this; Brain.Dead.1990.1080p.BluRay.x264-HD4U[rarbg] and thats just plain ugly for me. I'd like t... |
Another find whitout regex
find . -maxdepth 2 -type d -name '*.*' ! -name '.*'
| finding folders containing but not starting with a . (dot) |
1,308,650,780,000 |
How to merge 2 columns in a file alternatively? See below example.
inputfile:
sam jam
tommy bond
expected_output:
sam
jam
tommy
bond
|
Simply with awk:
awk '{ print $1 ORS $2 }' file
$1 and $2 - are the 1st and 2nd field respectively
ORS - Output Record Separator. The initial value of ORS is the string "\n" (i.e., a newline character)
The output:
sam
jam
tommy
bond
| How to merge 2 columns in a file alternatively? |
1,308,650,780,000 |
I'm using the rlwrap utility inside the following shell alias:
alias gp='rlwrap git push'
The purpose of this gp alias is to be able to use basic line editing commands such as C-a or C-e to get to the beginning or end of the command line, while I'm using the git push command.
I've also configured rlwrap to write the ... |
I have to give my credentials, username and password, and rlwrap saves them in ~/.config/rlwrap/git_history
Are you certain rlwrap indeed saves your password in its history file? By design, input that isn't echoed back is never put in the history list (in such a case, rlwrap will echo your keystrokes as ****) I chec... | How to prevent `rlwrap` from saving a password in an input history file? |
1,308,650,780,000 |
Suppose I entered the following thing into terminal:
wgets "link"
I will get the response:
No command 'wgets' found, did you mean:
Command 'wget' from package 'wget' (main)
I made a mistake, and the terminal warned me.
Is there a command that I can type after the terminal warned me, so that then it will execute t... |
Switch to zsh (installed by default on macOS and available as a package on all major Linux distributions, *BSD, and software collections for other Unix-like operating systems). It has autocorrect for command names.
% wgets
zsh: correct 'wgets' to 'wget' [nyae]? y
wget: missing URL
…
| Did you mean this command instead? (how to reply to this) |
1,308,650,780,000 |
I'm looking to use ex mode of vim for a script I'm trying to write, but I can't seem to figure out the syntax that will allow me to write multiple commands.
My code looks something like this:
ex -c 'normal! 2gg19|^V49gg59|y' geom.inc
So this just enters into ex mode for the file geom.inc, highlights a block of text, ... |
I was making silly errors. As @Jeff Schaller suggests above, multiple -c prompts will allow multiple commands. So, my working example looks like this.
ex -c 'normal! 2gg19|^V49gg59|y' -cwq geom.inc
Where I enter ex mode ex, prompt a command -c, define a block normal! 2gg19|^V49gg59|y (where normal! allows the use of ... | How are multiple commands given for ex from the command line? |
1,308,650,780,000 |
I am sorting files which have gene names and their expression values.
All files have same exact number of rows ,however after sorting there is a difference in the positioning of certain genes.
This is very weird.below are the sorted versions of two such files.
for example:
Cxx1c 25.1695
Cxxc1 15.2228
Cxxc4 0.95... |
You are currently sorting on the entire line, but it seems like you only want to sort on the first column. With the way your command is currently written, the columns will basically be concatenated together, eg:
Cyb5 157.426 -> Cyb5157426
Cyb561 0.425933 -> Cyb5610425933
vs
Cyb561 7.11003 -> Cyb561711003
Cyb5 ... | Sorting issues in Linux |
1,308,650,780,000 |
I have a command (php file) which takes, as an argument, the location of a file.
eg.
$ php ./ScriptName.php /my/file/location.txt
Sometimes I only need one or two words, so I don't really want to create the location.txt file just so I can reference it with the next command - I'd rather pipe it with the command somehow... |
You can use a variant of the /dev/fd/0 trick to pass a string to a script which expects a file name:
php ./ScriptName.php php://fd/0 <<<'mywords'
For example, script.php contains:
<?php
$handle=fopen($argv[1],"r");
echo "Read: ".fgets($handle);
fclose($handle);
?>
Running:
php script.php php://fd/0 <<<'Some... | inline heredoc instead of file |
1,308,650,780,000 |
I recently installed the brew command on my Debian machine to install tldr man pages on my system. The command looks useful for installing programs that aren't packaged by Debian, also it does not require sudo to install packages . However, there is a limitation: only a few packages can be installed through the comman... |
Is it possible? Yes. Both programs are open source.
Is it convenient? Not really.
Why?
Package managers work more or less like this:
They track packages installed on your system(and their version)
To do this, they specify their own format of packages(e.g. .deb), and use these packages as instructions on how to insta... | Is it possible to configure `brew` to install packages from Debian repositories? |
1,308,650,780,000 |
Let's say I have some CLI one-liner, which outputs some lines of text with space-separated parts. Those parts should logically be columns, but because of text width it doesn't look so.
How could I automatically format such output to make it pretty columns?
For example, I have output like
Alice param1 param2345 32768 5... |
With Linux column(1):
column -t <file.txt
With BSD rs(1):
rs 0 6 <file.txt
With awk(1):
awk 'FNR==NR { for(i=1; i<NF; i++) if(length($i)>w[i]) w[i]=length($i) }
FNR!=NR { for(i=1; i<NF; i++) $i=sprintf("%-" (w[i]+1) "s", $i); print }' \
file.txt file.txt
| How to adjust cli output into pretty columns |
1,308,650,780,000 |
Searching through passed Logfile with something like this:
cat /path/to/logfile | grep -iEw 'some-ip-address-here|correspondig-mac-adress-here'
This gives me all the passed log lines until now so I can see what has been. Now I also want to see what's going on so I need to exchange cat with tail -f giving me this:
t... |
You can use !!:* to refer to all the words but the zeroth of the last command line.
!! refers to the previous command, : separates the event specification from the word designator, * refers to all the words but the zeroth.
This is from the HISTORY EXPANSION section of bash(1).
wieland@host in ~» cat foo | grep bar
bar... | Is there a shortcut to rerun a command with arguments from last command (not cd, ls or echo) |
1,308,650,780,000 |
In many cases after I find a file using the find command I then want to open the file or cat it or maybe print it. How can I operate on the result from find? For example,
: find . -name "myfile.txt"
./docs/myfile.txt
: find . -name "myfile.txt" | less
does not work because it feeds the string "./docs/myfile.txt" to... |
Similar to @coffeeMug, this is the more up-to-date way to doing this as it is apparently faster:
find . -name "*.log" -exec ls -l '{}' +
I'll also point you to CommandLineFu, which is always helpful with these things.
| Access a file located with find |
1,308,650,780,000 |
I use CentOS 7 and I install anaconda and some tools, after that some basic command like clear which not work.
[zhilevan@localhost ~]$ clear
bash: clear: command not found...
when I echo $PATH I see below results
[zhilevan@localhost ~]$ echo $PATH
/usr/lib64/qt-3.3/bin:/home/zhilevan/perl5/bin:/usr/local/bin:/usr/lo... |
It looks as though some of your commands have been modified/removed outside of yum.
You need to reinstall the missing commands like so:
yum reinstall which
You can give multiple packages as you identify them:
yum reinstall which clear
If you find that lots of commands have been removed, it may be easier to reinstal... | Bash commands not found |
1,308,650,780,000 |
I want to determine the type and speed of my CPU so I executed the CPU command, However, I have some confusion, so from my output I can't really determine what is my CPU type and my speed is 1600 MHZ, is that right ?
I used
cat /proc/cpuinfo
and I got that my model name is Intel(R) Core(TM)2 Duo CPU , is that my c... |
I never knew about the lscpu command.
The man page says its based on the first CPU only. The "rate" may "change".
seems the lscpu is under change -- newer ones have a -V (--version) option, on my ubuntu 15.04 system it says:
leisner@t7400:/tmp$ lscpu --version
lscpu from util-linux 2.25.2
Model name: Inte... | Type and the speed of CPU using the lscpu command |
1,308,650,780,000 |
So here's the deal, my girlfriend wants me to transfer all of her photos off from her iPhone onto her laptop (on which we are running Ubuntu 14.04). All of the dedicated programs I tried to do this with did not work, so I just copied the entire DCIM/ folder, which contains all of the pictures on her iPhone. My predica... |
#!/bin/bash
appledir="$HOME/Pictures/DCIM/101APPLE"
jpgname="5003.JPG"
for dir in "$appledir"/*
do if [[ -d "$dir" ]]
then
newfile="$appledir/${dir##*/}"
mv "$dir"/5003.JPG "$newfile.tmp" &&
rmdir "$dir" &&
mv "$newfile.tmp" "$newfile"
fi
done
With an i... | Moving and renaming hundreds of .jpg files, all named 5003.jpg |
1,308,650,780,000 |
Is there a way to invoke or know a different clock or time on the CLI. The thing is I'm on UTC+5:30 time but at times need to know time in different time-zones. If there is a CLI way in which this can be known would be helpful.
|
As several others have mentioned, the TZ environment variable is what affects the output of date. However, in most cases you won't want to leave TZ changed; you will just want to see the time in that timezone, leaving your environment unaffected afterwards.
For that purpose, the best tool to use is env. From the env... | how to get a different time-clock on CLI apart from your time-zone? |
1,308,650,780,000 |
Is there a way to capture all commands executed in a bash or even better in sh?
I need a wrapper script that gets called everytime a command is executed. Like when I type cd /home/ I want my wrapper script command_wrapper.sh to be called. Inside I want to cancel the command or call another command.
#!/bin/sh
#comman... |
You can use the DEBUG trap to do this. In this trap, $BASH_COMMAND contains the command last executed.
trap 'echo "you tried to call the command [$BASH_COMMAND]"' DEBUG
Note that, if you are executing commands as part of your prompt or $PROMPT_COMMAND, the trap will run on these as well. You can add checks to see if ... | bash on command event (or shell) |
1,308,650,780,000 |
I'm using bash, and I want to be able to execute a script just by typing its name as a command, same as pwd for example.
Is there a specific directory where I need to save my script to, or any other system files I need to edit to achieve this?
|
You have to install that script in one of the directories of $PATH. Use (echo $PATH) to see the directories of $PATH
That means either copy the script to
Or make a symbolic link to the script inside one of the directories of $PATH
Or append the script directory to $PATH
export PATH=$PATH:<script directory>
| How can I create new shell commands? |
1,308,650,780,000 |
I am trying to write a command along the lines of the following:
vim -c "XXXXXX" myFile
Instead of the "XXXXX" I want to supply some commands to vim to add some text to an arbitrary point in the file, both by specifying an exact line number and, in a different scenario, by searching for a specific line and then inser... |
Command line ranges can be use to select a specific line that needs to be edited.
Then substitute pattern can be used to perform the edit (append).
For example, to append text "hi" at the begining of line 3:
vim -c "3 s/^/hi/" -c "wq" file.txt
To append text "hi" at the end of line 3:
vim -c "3 s/$/hi/" -c "wq" file.... | How do I use vim on the command line to add text to the middle of a file? |
1,308,650,780,000 |
How do you view a sql.gz file as plain text SQL from the command line?
I want to read the SQL statements stored in a .sql.gz file, from the command line on the server. I've tried tar -xzvf, but get tar: This does not look like a tar archive. cat returns garbage because it's compressed.
|
gunzip -c <filename> | less
or
zcat <filename> | less
| How do you view a sql.gz file as plain text SQL from the command line? |
1,308,650,780,000 |
When I run in my terminal:
alias
a list with all my aliases (defined in ~/bashrc and ~/.bash_aliases files) will be displayed on my terminal. That's nice and as expected!
But when I run:
bash -c "alias"
there is no output, so no aliases. First I thought that ~/.bashrc file is not sourced in the second case, so I ran... |
You need an interactive shell for alias definitions:
bash -i -c "alias"
| Why are aliases missing inside of bash command? |
1,308,650,780,000 |
I can paste the contents of a file into a command using cat and backticks:
ls `cat filenames`
Is there a way to do the reverse - to turn a string into a (temporary) filename?
gcc -o cpuburn `uncat "main(){while(1);}"`.c
|
You can pass the source code on gcc's standard input. Since gcc isn't given a file name, you need the -x option to let it know what the output language is. You can pass input via a here string (most convenient for a single line), a here document, or a pipe.
gcc -o cpuburn -x c - <<<'main(){while(1);}'
If you need a f... | Is there a command which creates a temporary file containing the arguments passed to it? |
1,308,650,780,000 |
I have a flash usb drive and up till now it has worked well. Recently I recorded iso to it using dd. Now I want to delete it.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
.......
sdb 8:16 1 14.6G 0 disk
└─sdb1 8:17 1 14.5G 0 part /media/alex/ARCH_201404
sr0 11:0 1 1024M 0 rom
$ moun... |
You only zeroed the first 4kb of the partition. Usually all file systems keep a few unused blocks at the start of their partition in order to give space to boot loaders that might be installed on the partition itself. I think that at least 16 blocks are always kept unused.
You copied, with dd, a file system of type IS... | Unable to remove the files from an usb drive (neither by dd /dev/zero nor by rm -r) |
1,308,650,780,000 |
Somebody helped me run a java program with the following (working) line of code. The zookeeper-3.4.5.jar exists in the working directory. What it is the meaning of the .: syntax here? Does that just mean current directory? I would have written this as java -cp "zookeeper-3.4.5.jar" but I'm not 100% sure this would do ... |
The . is the current directory. The : is the path separator, used to separate multiple paths in a single option/variable under *nix. This command line therefore adds both . and zookeeper-3.4.5.jar to the Java classpath.
| What is the meaning of the .: in this linux statement? |
1,308,650,780,000 |
If you were trying to run a package that is not installed, for example:
me ~: gparted
The program 'gparted' is currently not installed. You can install it by typing:
sudo apt-get install gparted
How can I run the sudo apt-get install gparted line as a command?
Not typing it, obviously.
|
You can enable it by adding this to your .bashrc
export COMMAND_NOT_FOUND_INSTALL_PROMPT=1
Giving you:
$ foo
The program 'foo' is currently not installed. You can install it by typing:
sudo apt-get install blah-blah
Do you want to install it? (N/y)
If you get a python error as in:
...
File "/usr/lib/python3/dist-... | Run last line of error message as a command |
1,383,332,844,000 |
I want to define a new ls command to do something like this
The first when i use ordinary ls command:
$ls
undergrade.AI undergrade.KDD
undergrade.AI2 undergrade.micro
undergrade.ANN undergrade.OOT
undergrade.autoMata undergrade.OS
undergrade.bulletin undergrade.parall... |
This should do what you want:
ls|sed 's/\..*//'|sort -u|column
If your shell has the width of your terminal in $COLUMNS, then this is better:
ls|sed 's/\..*//'|sort -u|column -c $COLUMNS
| How to use `ls` to group and show only a first word of directory name? |
1,383,332,844,000 |
I'd like to know how many average lines are written to a file per minute.
|
You could do:
tail -fn0 the-file | pv -lri60 > /dev/null
That will give you a number of lines per second though.
Otherwise:
{
cat > /dev/null
while sleep 60; do
wc -l
done
} < the-file
(beware that won't be exactly accurate as the sleep 60 won't guarantee that is done exactly every 60 seconds).
| What command will generate average lines per minute? |
1,383,332,844,000 |
In Linux I always cd to a longish path and then run the script:
cd /scratch/someDir/someOthernestedDir/
./shellscriptName.sh
How can I avoid achieve typing this longish path and then executing the command with a single step?
Some thing like the below from any path should do what I want:
executeMyCommand
P.S: I am... |
There are three main ways of running your script without needing to specify the full path.
Add the directory containing your script to your $PATH. You will then be able to execute the script by name from any directory, just like any other program. If you are using csh, add this to your ~/.cshrc:
set path = ($path /sc... | How can I execute a shell script that exists in a longish path with a single command without first cd'ing to the directory? |
1,383,332,844,000 |
I would like to configure bash so that when I execute command (preferably from a list of commands, not any command) without an argument, it takes the argument of previous command.
So, for example I type emacs ~/.bashrc, then when I enter source, bash executes source ~/.bashrc. I know it's possible but I don't know whe... |
You can press Space then Meta+. before pressing Enter. This has the advantage that you can use it even with commands that make sense when applied to no argument. For source, use . to type less.
If you're old-school, you can use !^ instead to recall the first argument from the previous command, or !$ to recall the last... | Configure bash to execute command with last argument when no argument was provided |
1,383,332,844,000 |
Possible Duplicate:
creating abbreviations for commonly used paths
I'm new to the Linux platform. Is there any way to rename the commands available in Linux.
For example, I use the clear command a lot and instead of typing it every time I want to rename it as just c. Is this possible ?
|
You can create an alias, as you have figured that out, or just use the key combination Ctrl+L to clear the screen contents.
| Change command name in Linux [duplicate] |
1,383,332,844,000 |
Does anyone know if there is a way reproducing the same behaviour many text editors provide for colour-highlighting the syntax operators such as brackets or curly brackets. It would be very useful for complex one-liners in the terminal.
Example of the functionality I am talking about (from VIM).
|
When writing complex one liners in bash, it is handy to use readline's edit-and-execute-command (bound to C-xC-e by default in emacs mode). Hitting C-xC-e opens current commandline in the editor of your choice with all its fancy features. After saving it, bash will execute the contents as shell commands.
Alternatively... | Is there a way of color-highlighting paired brackets in shell (bash)? |
1,383,332,844,000 |
I was playing around with Pushover, and had the thought that it would be cool if I could use it as an argument on any random command, so that it would run a pushover script at the end of the task, regardless of what that task was.
I have no idea if it's possible, or how I would go about it, but I'd like to learn.
Th... |
You do it the other way around:
$ pushover-notify "This is my message" command arg1 arg2
Your script pushover-notify could be something like this:
#!/bin/sh
TOKEN=your_token
USER=your_user
MSG="$1"
COMMAND="$2"
shift 2
if "$COMMAND" "$@" ; then
# here run your send-message script, with message "$MSG". for example:... | What would it take to add a command to run a script at the completion any given random task? |
1,383,332,844,000 |
Possible Duplicate:
What do the numbers in a man page mean?
I see functions referred to with numbers in the parenthesis in documentation. What does this mean? It takes one argument?
|
Unix manual pages come in "sections"; see man man for what they mean (on most platforms; I assume yours will document it in there.)
Section 1 is "user commands", and that means "the manual page from section 1 for ls".
You will find that crontab(1) and crontab(5) are an example of where you have more than one page unde... | What is the significance of the "1" in ls(1)? [duplicate] |
1,383,332,844,000 |
With the following bash command that crops an image, I would like to loop through from 02 to 18, using a single line command.
convert TOS28_Page_02.jpg -crop 990x1500+0+0 TOS28_Page_02a.x.jpg
|
for((i=2;i<19;++i));do printf "convert TOS28_Page_%02d.jpg -crop 990x1500+0+0 TOS28_Page_%02da.x.jpg;" $i $i;done|sh
| Crop images in single line |
1,383,332,844,000 |
Is there an easy way to see how lines are changing in a file?
For example, assume I have this "my.log" file:
cpu1 cpu2 cpu3 cpu4
5 3 3 6
5 3 3 6
5 0 3 6
3 0 6 6
5 3 3 0
From the command line, I want to enter something like "cat my.log | showchanges" and then... |
awk '{ bak=$0; for(i=1; i<=NF; i++)$i=($i==tmp[i]?"-":$i)
split(bak, tmp)
}1' infile
cpu1 cpu2 cpu3 cpu4
5 3 3 6
- - - -
- 0 - -
3 - 6 -
5 3 3 0
To keep the records indentation (fields width of 4):
awk '{ bak=$0; for(i=1; i<=NF; i++)$i=sprintf("%4s", ($i==tmp[i]?"-":$i))
split(bak, tmp)
}1' infile
cp... | Show changes between consecutive lines of a file |
1,383,332,844,000 |
I noticed the error this morning, but I don't think I have changed anything last night, so I am very confused right now. Perhaps I updated some utilities on my system and it somehow broke the back compatibility. Basically I got a math: Error: Missing operator error when using tab completion.
Say I type fish, and hit T... |
The error goes away after I remove the line set -px PATH $PLAN9/bin. I guess it was because I accidentally shadowed some system utilities with its counterpart in Plan 9 from User Space.
Another workaround is to use set -ax PATH $PLAN9/bin instead. By using -a, the directory $PLAN9/bin is appended to $PATH (as opposed ... | Fish shell reports "math: Error: Missing operator" on tab completion |
1,383,332,844,000 |
Suppose I have a directory structure like this:
projects/
project1/
src/
node_modules/
dir1/
dir2/
dir3/
file
project2/
node_modules/
dir4/
Starting from projects/ I want to delete the contents of all node_modules/ directories, but I do not want to delete the node_modules... |
The following will delete all files and directories within a path matching node_modules:
find . -path '*/node_modules/*' -delete
If you would like to check what will be deleted first, then omit the -delete action.
| How to recursively delete the contents of all "node_modules" directories (or any dir), starting from current directory, leaving an empty folder? |
1,383,332,844,000 |
I always have been using sort -u to get rid of duplicates until now.
But I am having a real doubt about a list generated by a software tool.
The question is: is the output of sort -u |wc the same as uniq -u |wc?
Because they don't yield the same results. The manual for uniq specifies:
-u, --unique only print unique l... |
No, they're not the same. For one, sort would sort the list first; and second, uniq -u prints only those lines that are "unique" in each given run, the ones that don't have an identical input line before or after them.
$ printf "%s\n" 3 3 2 1 2 | sort -u
1
2
3
$ printf "%s\n" 3 3 2 1 2 | uniq -u
2
1
2
See also:
Wh... | Difference between sort -u and uniq -u |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.