upgrading xubuntu to 24.04, fresh install, but I’d like to copy the output of both dpkg -l and history to a usb stick.
About history: will it copy all commands I executed on all tabs? I work with several tabs simultaneously.
ETA: thank you for all your input, problem has been solved.
First, use
lsblk
to list your block devices. Note the path containing your usb device. e.g./dev/sdb1
Next mount the device to an existing folder or create a new one.
mkdir -p /mnt/thumbstick mount /dev/sdb1 /mnt/thumbstick
Now you can pipe the dpkg output to the usb device.
dpkg -l > /mnt/thumbstick/packages.txt
Finally, you can unmount the stick to ensure everything is flushed. (optional)
umount /mnt/thumbstick
thanks, this worked
in case it’s not clear from the comments . and sorry for repeating if it is, but this >> thing is a really useful terminal thing to know in many cases.
>>
will trap and redirect terminal output.So consider any old commmand and its output:
echo abcThis invokes the echo command and echo outpts “abc” to terminal.
If we add on >> we can catch and redirect the output:
echo abc >> blah.txt
Will capture the output “abc” into the file.
Note this is an APPEND operation, so run it twice to the same output file and you’ll add more and more output to new lines at the end of the same file.
thank you, this also worked
plug in the usb, run the command lsblk. it will list all the block devices that the computer can see.
look for your usb by size, etc. the column “name” after lsblk will be the device and partition (for example sdc and sdc1). the “name” entry on the same line as your usb’s size with a number after it is the partition, the one without a number is the usb itself. you will be mounting the partition.
make a directory in /var to mount the usb stick in with mkdir /var/usb. that command writes to the /var section of your filesystem, where /var-iable files live. mount the usb stick at that location with mount /dev/[your partition, like sdc1] /var/usb.
example: my usb was /dev/sdc1, so for me it’s mount /dev/sdc1 /var/usb. the syntax is mount [device] [location].
run any command with |tee -i /var/usb/target_filename.txt after it to both output the command to the screen and send it to a file on the usb. that command writes the output of whatever command preceeds it to the specified file in /var/usb.
example: ls / |tee -i /var/usb/target_filename.txt would write the output of the command “ls /”, listing the contents of the root of your filesystem, to /var/usb/target_filename.txt as well as displaying it. if /ver/usb/target_filesystem.txt doesn’t exist, it will be created.
use different files on different commands so you don’t write over what you have or pass -a to the tee command so it will -a-ppend the text it writes to the end of the file. ex: |tee -ia /var/usb/filename.txt
for the specific command you asked about, it would be dpkg -l |tee -i /var/usb/target_filename
to write out your command history, use the “history” command. it can be given the tee treatment as well. to access a users history look at their $HISTFILE. if you don’t know what interpreter they’re using, assume bash and look for ~/.bash_history
thanks for the input
Did you get it straightened out?
yup
@merompetehla
Mount the usb in any directory
send the output of any command to a file
dpkg -l >> file.txt
Move those files to the directory were the usb is mountedudisksctl for mounting.
I’m pretty sure the history command outputs only commands from the shell/tab it’s invoked in plus the commands already saved to the shells history file. Commands are not always saved to the file immediately. So to make 100% sure, you have to clean exit all shells before using history.
You can easily test this by using a unique command (like: echo 123) in one shell and history in another.
Also the shell probably has a man page detailing config options that affect the history.