02 March 2026

How to mirror android mobile phone screen to ubuntu laptop screen?

Here are the most practical and popular ways to **mirror your Android phone screen** to an **Ubuntu laptop** as of 2026. The methods vary in latency, wireless capability, and ease of setup.

### Best Overall Method (Recommended): Use **scrcpy** (low latency, free, open-source)

**scrcpy** remains the gold standard for mirroring + controlling Android → Linux in 2025–2026.  
It has very low latency (~30–70 ms), supports control with mouse & keyboard, works wired or wireless, and requires **no app** on the phone.

#### Quick wired setup (USB) – most reliable & lowest latency

1. **Enable USB debugging on Android**  
   Settings → About phone → tap Build number 7× → Developer options → USB debugging (ON)

2. **Install scrcpy on Ubuntu**  
   Most Ubuntu versions (22.04 / 24.04 / 25.04 / 26.xx) can do this easily:

   ```bash
   sudo apt update
   sudo apt install scrcpy adb
   ```

   (If the version in repositories is old, you can install the latest from GitHub releases or PPA.)

   Alternative one-liner for latest version (2025–2026 style):

   ```bash
   sudo apt install -y git meson ninja-build libsdl2-dev adb wget gcc pkg-config
   git clone https://github.com/Genymobile/scrcpy
   cd scrcpy
   ./install_release.sh
   ```

3. **Connect phone via USB cable**

4. **Authorize the computer** on the phone (pop-up appears → Allow)

5. **Run it**

   ```bash
   scrcpy
   ```

   That's it — your phone screen appears in a window. You can click, type, drag, etc.

   Nice extra flags people use a lot:

   ```bash
   scrcpy --turn-screen-off          # turns phone screen black (saves battery)
   scrcpy -m 1024                    # limit max resolution to 1024 (less lag on slow machines)
   scrcpy --window-title="My Phone" --always-on-top
   scrcpy --no-audio                 # if you don't want sound
   ```

#### Wireless (Wi-Fi) scrcpy (after initial USB setup)

1. Connect phone via USB once and run:

   ```bash
   adb tcpip 5555
   ```

2. Disconnect USB cable

3. Find your phone's IP (Settings → About phone → Status or Wi-Fi settings)

4. Connect wirelessly:

   ```bash
   adb connect 192.168.1.123:5555
   scrcpy
   ```

   (Replace with your phone's IP)

### Good Wireless-Only Alternative: **AirDroid Cast** (browser-based)

If you want something without USB ever and don't mind slightly higher latency:

1. On phone → install **AirDroid Cast** from Play Store

2. On Ubuntu → open Firefox/Chrome → go to https://webcast.airdroid.com

3. Scan QR code or enter 9-digit code shown in browser

4. Accept on phone

→ Works wirelessly, decent quality, but usually more delay than scrcpy and sometimes has resolution/bitrate limits on free tier.

### Other Options in 2025–2026

| Method              | Latency | Wireless? | Control phone? | Install on phone? | Recommendation |
|---------------------|---------|-----------|----------------|-------------------|----------------|
| scrcpy              | ★★★★★   | Yes (after setup) | Yes            | No                | Best overall   |
| AirDroid Cast       | ★★★☆☆   | Yes       | Yes            | Yes               | Easiest wireless-only |
| gnome-network-displays + MiracleCast | ★★☆☆☆   | Yes       | No             | No                | Complicated, often buggy |
| Vysor (chrome ext)  | ★★☆☆☆   | Yes       | Yes            | Yes               | Ads in free version |
| KDE Connect + plugin| ★★★☆☆   | Yes       | Limited        | Yes               | Casual use only |

**Quick choice guide**:
- You want **lowest latency + full control** → **scrcpy USB** (or wireless after setup)
- You hate cables and want something dead simple → **AirDroid Cast**
- You already use KDE Connect → try its screen sharing (but expect higher latency)

Let me know your Ubuntu version and whether you prefer wired or wireless — I can give more exact commands if needed!

 

Grok, after I ran the 'Alternative one-liner for latest version (2025-2026 style)', I got the following message, with an error message -

 

Did not find CMake 'cmake' Found CMake: NO Run-time dependency libavformat found: NO (tried pkgconfig) app/meson.build:116:4: ERROR: Dependency "libavformat" not found, tried pkgconfig A full log can be found at /home/shermanchen/scrcpy/build-auto/meson-logs/meson-log.txt

 

The error you're seeing (ERROR: Dependency "libavformat" not found, tried pkgconfig) occurs because the scrcpy build requires FFmpeg development libraries (specifically the libavformat component from FFmpeg), but those dev packages weren't installed by your initial command.

Your Ubuntu version appears to be 24.04 LTS (Noble) based on the package versions and repository paths in the output.

Quick Fix: Install the missing FFmpeg dev dependencies

Run this command to add the required build packages (these provide libavformat, libavcodec, libavutil, etc.):

Bash
sudo apt update
sudo apt install -y \
    libavcodec-dev \
    libavdevice-dev \
    libavformat-dev \
    libavutil-dev \
    libswresample-dev
  • These are the key ones for audio/video handling in scrcpy.
  • You already have most other deps (like meson, ninja-build, libsdl2-dev, etc.) from your first run.

Then retry the build

After installing those, go back to your cloned directory and re-run the installer script:

Bash
cd ~/scrcpy   # or wherever you cloned it
./install_release.sh
  • It should now detect libavformat via pkg-config and complete the build.
  • The script downloads the latest server JAR, builds the client binary, and installs everything (usually to /usr/local/bin/scrcpy).

 

 Grok, after I ran the './install_release.sh', I got the following message.

libusb1.0 not found.

 

Did not find CMake 'cmake' Found CMake: NO Run-time dependency libusb-1.0 found: NO (tried pkgconfig) app/meson.build:128:20: ERROR: Dependency "libusb-1.0" not found, tried pkgconfig

 

 

The new error (ERROR: Dependency "libusb-1.0" not found, tried pkgconfig) means the build now detects your FFmpeg libs correctly (great progress from last time!), but it's missing the libusb-1.0 development files — specifically the .pc file that Meson/pkg-config uses to find include paths and linker flags for libusb.

On Ubuntu 24.04 (Noble), the package that provides this is libusb-1.0-0-dev.

Step to fix it

Run this:

Bash
sudo apt update
sudo apt install libusb-1.0-0-dev
  • This installs the headers (/usr/include/libusb-1.0/libusb.h), the pkg-config file (/usr/lib/x86_64-linux-gnu/pkgconfig/libusb-1.0.pc), and static/shared libs needed for building.
  • It's a very small package (~few hundred KB) and safe/standard.

After installing

  1. Clean the previous failed build (good practice to avoid stale state):

    Bash
    cd ~/scrcpy
    rm -rf build-auto   # or whatever the build dir was (from your log: build-auto)
  2. Re-run the installer:

    Bash
    ./install_release.sh

It should now pass the libusb check, finish compiling the client binary, and install scrcpy (usually to /usr/local/bin).

Verify success

After it completes:

Bash
scrcpy --version

Should output something like scrcpy 3.3.4 (or the exact version it built).

If it still complains about libusb (very unlikely), you can manually check pkg-config sees it:

 

 shermanchen@serverlenovo:~/scrcpy$ scrcpy --version
scrcpy 3.3.4 <https://github.com/Genymobile/scrcpy>
Dependencies (compiled / linked):
- SDL: 2.30.0 / 2.30.0
- libavcodec: 60.31.102 / 60.31.102
- libavformat: 60.16.100 / 60.16.100
- libavutil: 58.29.100 / 58.29.100
- libavdevice: 60.3.100 / 60.3.100
- libusb: - / 1.0.27
 
Success! Thank you so much!
 
Next, how do I share my Android phone screen with my Ubuntu laptop screen, please?

 

 Congratulations on successfully building and installing **scrcpy 3.3.4** — that's the latest version as of early 2026!

Now let's get your Android phone screen mirrored to your Ubuntu laptop. scrcpy supports two main modes: **USB** (simplest, lowest latency) and **wireless** (after a quick setup).

### Prerequisites (do this once)
1. On your **Android phone**:
- Go to **Settings → About phone** → tap **Build number** 7 times to unlock Developer options.
- Go back to Settings → **System** → **Developer options** → enable **USB debugging**.
- (Optional but recommended for wireless later: also enable **Wireless debugging** if your Android is 11+.)

2. Connect your phone to your Ubuntu laptop with a **USB cable** (good quality cable helps avoid issues).

3. On the phone, a popup should appear: "Allow USB debugging?"
→ Check "Always allow from this computer" → tap **Allow**.

4. In your terminal, verify the connection:
```
adb devices
```
You should see something like:
```
List of devices attached
1234567890abcdef device
```
If it says "unauthorized", re-check the popup on the phone.

### Option 1: Mirror via USB (easiest & lowest latency – recommended to start with)
Just run:
```
scrcpy
```

Your phone screen should instantly appear in a window on Ubuntu.
You can control the phone with your mouse (click = tap) and keyboard.

Useful quick options (add them to the command):
- `scrcpy --turn-screen-off` → turns phone screen black (saves battery, still mirrors)
- `scrcpy -m 1024` → limits resolution to 1024px max (less lag on slow Wi-Fi later)
- `scrcpy --no-audio` → disable sound forwarding if not needed
- `scrcpy -w` or `--stay-awake` → keep phone awake
- `scrcpy --window-title="My Phone" --always-on-top`

Full example with popular flags:
```
scrcpy --turn-screen-off --stay-awake -m 1200
```

To quit: close the window or press **Ctrl+C** in terminal.

### Option 2: Mirror wirelessly (no cable after initial setup)
Both devices **must be on the same Wi-Fi network**.

**Method A: Classic ADB TCP/IP (works on all Android versions)**
1. Connect via USB once more (if not already).
2. Enable ADB over network:
```
adb tcpip 5555
```
Phone may show a confirmation — allow it.

3. Disconnect the USB cable.

4. Find your phone's IP address:
- Settings → About phone → Status → **IP address**
(or Settings → Network & internet → Wi-Fi → tap your network → Advanced → IP address)
Example: `192.168.1.105`

5. Connect wirelessly:
```
adb connect 192.168.1.105:5555
```
Should say "connected to 192.168.1.105:5555"

6. Launch mirroring (no cable needed anymore):
```
scrcpy
```
(or with flags like above)

To disconnect wireless mode later: `adb disconnect` or just reboot phone.

**Method B: Wireless debugging pairing (Android 11+ only – no initial USB needed after first time)**
1. On phone: Developer options → **Wireless debugging** → tap **Pair device with pairing code**.
- It shows: IP address & port (e.g. 192.168.1.105:37123) and a 6-digit pairing code.

2. In terminal on Ubuntu:
```
adb pair 192.168.1.105:37123 123456
```
(replace with your IP:port and code)

3. After pairing succeeds, connect normally:
```
adb connect 192.168.1.105:5555
scrcpy
```

Wireless usually has slightly higher latency (~50-150 ms vs ~30-70 ms on USB) and needs good Wi-Fi. If it lags, lower resolution with `-m 800` or `-m 960`.

### Troubleshooting quick tips
- No window appears? → Run `scrcpy` and check terminal for errors.
- "ERROR: Could not open device" → re-allow USB debugging or try another cable/port.
- Wireless fails? → Ensure same Wi-Fi, firewall allows ADB (port 5555), or restart adb: `adb kill-server && adb start-server`.
- Want to record screen? → `scrcpy --record=file.mp4`

Enjoy the mirroring — it's one of the smoothest ways to use your phone from the laptop!
If anything doesn't work, paste the exact error from the terminal and I'll help debug.


 

01 March 2026

on ubuntu, how can I check the author, date/time created, information of a .docx file?

Using ExifTool (Recommended)
ExifTool provides comprehensive metadata, including author, creation date, modification time, and last saved by.
  1. Install ExifTool (if not already installed):
    bash
    sudo apt update
    sudo apt install exiftool
    
  2. Run the command to view the metadata:
    bash
    exiftool your_document.docx
    
  3. To look for specific fields (like Author or Dates) quickly, you can use grep:
    bash
    exiftool your_document.docx | grep -i "Author"
    exiftool your_document.docx | grep -i "Date"
    

26 February 2026

How can i use a special character as the HTML list item marker?

HTML 

<ul class="special-bullets">
  <li>Item one</li>
  <li>Item two</li>
  <li>Item three</li>
</ul>


CSS

.special-bullets {
  list-style-type: none;      /* remove default bullet */
  padding-left: 1.4em;        /* adjust indent as needed */
}

.special-bullets li::marker {
  content: "★ ";              /* ← your special character + space */
  /* content: "✔ "; */
  /* content: "➜ "; */
  /* content: "🚀 "; */        /* emoji also works */
  color: #e91e63;             /* optional: color the marker */
  font-size: 1.1em;           /* optional: size */

 

You can also style the number in the same way:

ol.fancy-numbers li::marker {
  content: counter(list-item) ". ";   /* default is "1. " */
  color: navy;
  font-weight: bold;

 

23 February 2026

How to shrink file size of a pdf file?

sudo apt update
sudo apt install ghostscript

The Compression Command
Use the following command to compress the PDF to a "screen" quality, which is usually sufficient for viewing on monitors or emailing and will easily bring a 3MB file below 2MB:
bash
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
  • input.pdf: Replace with your original file name.
  • output.pdf: The name of the new compressed file.
Alternative: Better Quality (eBook)
If the /screen setting makes the text look too blurry, try /ebook (150 dpi), which balances good quality with a smaller file size:
bash
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Other Options
  • -dPDFSETTINGS=/screen: 72 dpi, lowest quality, smallest size (best for >2MB requirement).
  • -dPDFSETTINGS=/ebook: 150 dpi, medium quality, better for reading.
  • -dPDFSETTINGS=/printer: 300 dpi, high quality, likely to keep the file over 2MB.
Note: If the PDF contains text only, the file size reduction may be limited.


Knowing port number, how to kill a process which is using that port?

  • Find what's sitting on the port:  

    $ sudo lsof -i :8000 (Replace 8000 with your port)

  • Kill that specific listener:  

    $ sudo kill -9 <PID_FROM_LSOF>


If I am running -

$ gunicorn --bind 0.0.0.0:8000 app:app
[2026-02-23 10:38:25 -0500] [250191] [INFO] Starting gunicorn 25.1.0
[2026-02-23 10:38:25 -0500] [250191] [INFO] Listening at: http://0.0.0.0:8000 (250191)
[2026-02-23 10:38:25 -0500] [250191] [INFO] Using worker: sync
[2026-02-23 10:38:25 -0500] [250191] [INFO] Control socket listening at /home/shermanchen/dev/convShop2/gunicorn.ctl
[2026-02-23 10:38:25 -0500] [250193] [INFO] Booting worker with pid: 250193

 

When I run lsof, I get -

$ sudo lsof -i :8000                           
COMMAND     PID        USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME                            
gunicorn 250191 shermanchen    3u  IPv4 1077472      0t0  TCP *:8000 (LISTEN)                 
gunicorn 250193 shermanchen    3u  IPv4 1077472      0t0  TCP *:8000 (LISTEN) 

 

If I kill the 'booting worker' pid 250193, the gunicorn will not be killed.  I have to kill the 'listening' pid 250191, to kill the gunicorn process.

$ sudo kill -9 250191

  

If I use ps, I got

$ ps aux | grep gunicorn                       
sherman+  250690  0.0  0.0   9824  2172 pts/1    S+   10:45   0:00 grep --color=auto gunicorn 
 

Killing pid 250690 will not kill the gunicorn process.

Flask Tutorial - Build a Flask Python Web App from Scratch

https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3

 

 

18 February 2026

How to sort by time the result of the $ find command?

$ find . -iname "applied*" -type f -printf '%T+ %p\n' | sort -r

 

$ find . -iname "applied*" -type f -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort -r 

11 February 2026

In vim, how to make the first letter of every word into uppercase?

https://dev.to/gokayburuc/vim-regex-tricks-capitalize-every-first-letter-526j

To capitalize the first letter of each word in a sentence, use the following Vim command:

:s/\<\w/\u&/g

Explanation of the Command

  • :s/ starts the substitution command in Vim, which is used to find a pattern and replace it with a specified value.
  • \< matches the beginning of a word. In Vim, a word is defined as a sequence of letters, digits, or underscores.
  • \w matches any word character (letters, digits, or underscores).
  • \u is a replacement flag in Vim that converts the next character in the replacement string to uppercase.
  • & represents the entire matched text from the search pattern (in this case, the first character of each word).
  • /g applies the substitution globally, ensuring every matching occurrence in the line is processed rather than just the first one.

By running this command, Vim will capitalize the first letter of each word in the specified text.

 

 

 

01 February 2026

How to crop a video on Ubuntu?

ffmpeg -i input.mp4 -vf "crop=1200:626:279:89" -c:v libx264 -crf 20 -c:a copy output.mp4


To crop a video on Ubuntu, you use FFmpeg’s
crop filter. Cropping is different from resizing; it’s like taking a pair of scissors to the video frame to cut out a specific area (like removing a watermark or focusing on a specific person).

The logic for cropping is: crop=width:height:x:y


1. The Basic Crop Command

If you know the exact dimensions you want to keep, use this:

Bash
ffmpeg -i input.mp4 -vf "crop=1280:720:0:0" -c:a copy output_cropped.mp4
  • 1280: The width of the "box" you want to keep.

  • 720: The height of the "box" you want to keep.

  • 0: The X coordinate (distance from the left edge) where the box starts.

  • 0: The Y coordinate (distance from the top edge) where the box starts.


2. Common "Real World" Examples

To crop a square from the center (great for social media):

Bash
ffmpeg -i input.mp4 -vf "crop=ih:ih" -c:a copy output_square.mp4

(Note: ih stands for "Input Height." This tells FFmpeg to make the width equal to the height.)

To cut the video in half (keep only the right side):

Bash
ffmpeg -i input.mp4 -vf "crop=iw/2:ih:iw/2:0" -c:a copy output_right_half.mp4

3. How to find your coordinates (The Easy Way)

Trying to guess "X" and "Y" coordinates in a terminal is hard. Here is a trick to do it visually:

  1. Open your video in VLC.

  2. Go to Tools > Effects and Filters.

  3. Go to Video Effects > Crop.

  4. Type in numbers until the video looks exactly how you want it.

  5. Write down those numbers (Left, Right, Top, Bottom) and use them in this FFmpeg command:

Bash
# If you found: Left=100, Top=50, Width=800, Height=600
ffmpeg -i input.mp4 -vf "crop=800:600:100:50" -c:a copy output_cropped.mp4

Important Tips:

  • Re-encoding: Because you are changing the actual picture, FFmpeg has to re-encode the video. I didn't include quality flags above to keep it simple, but for the best result, add -crf 20: ffmpeg -i input.mp4 -vf "crop=w:h:x:y" -c:v libx264 -crf 20 -c:a copy output.mp4

  • Even Numbers: Just like before, H.264 (MP4) loves even numbers. If you get an error, make sure your width and height are divisible by 2.


How to convert a .webm video into a .mp4 one?

ffmpeg -i output_trimmed.webm -c:v libx264 -crf 23 -preset medium -c:a aac output.mp4

How to trim a video on Ubuntu?

ffmpeg -i toAi.webm -ss 02:42 -to 05:59 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output_trimmed.webm

30 January 2026

How to move all the files in a directory to another directory on Linux

Gemini, I used the command -

$ ls -alhSp | grep -v /

, and got a list of files in the current directory.

What command can I use to move the files in the above list to another directory, please?


That is a very specific (and clever) command! You're using ls to list all files, sorting them by size (-S), adding a trailing slash to directories (-p), and then using grep to filter out anything with a slash.

Essentially, you've isolated just the regular files in your current folder, ranked from largest to smallest.

To move that specific list to another directory, you have a few options depending on how "clean" you want the process to be.


Method 1: The "Xargs" Approach (Recommended)

This is the most efficient way to take the output of one command and pipe it into another. We use the -I flag to create a placeholder (often {}) for the filenames.

Bash
ls -alhSp | grep -v / | awk '{print $9}' | xargs -I {} mv {} /path/to/destination/
  • awk '{print $9}': This is necessary because your original command uses -l (long format). awk grabs just the filename (the 9th column) so mv doesn't try to move the file permissions or timestamps.

  • xargs -I {}: This tells the system: "Take each filename and put it where the {} is in the next command."

Method 2: The Simple "Wildcard" (If you don't need the sort order)

If your goal is simply to move all files but no folders and you don't actually care about the size sorting from your original command, a simple loop is often safer:

Bash
for file in *; do [ -f "$file" ] && mv "$file" /path/to/destination/; done

⚠️ A Note on File Names

If any of your files have spaces in their names, the ls | grep method can get messy. When dealing with complex file movements, using find is generally the "Gold Standard" because it handles hidden characters and spaces much better:

Bash
find . -maxdepth 1 -type f -exec mv {} /path/to/destination/ \;
  • -maxdepth 1: Prevents it from looking into subfolders.

  • -type f: Ensures only files are moved (ignoring directories).


Which one should you use?

If you want...Use...
To keep using your ls logicMethod 1 (with awk)
The safest/fastest wayThe find command
To avoid complex syntaxMethod 2 (The loop)

Would you like me to explain how to modify that command to only move files over a certain size?


Yes, please. Thank you.

 

 

Since you are already using ls -S (sort by size), we can refine your pipeline to filter for specific size thresholds.

To do this effectively, we’ll swap ls for the find command. While ls is great for looking at files, find is a powerhouse for filtering them by attributes like size, age, or type.


Using find for Specific Sizes

This is the most reliable method. You can specify "greater than" (+) or "less than" (-) a certain size.

To move files larger than 100MB:

Bash
find . -maxdepth 1 -type f -size +100M -exec mv {} /path/to/destination/ \;

To move files smaller than 50KB:

Bash
find . -maxdepth 1 -type f -size -50k -exec mv {} /path/to/destination/ \;

Breakdown of the logic:

  • .: Look in the current directory.

  • -maxdepth 1: Don't go digging into subfolders.

  • -type f: Only look for files (this replaces your grep -v / logic).

  • -size +100M: The filter. Use k for Kilobytes, M for Megabytes, or G for Gigabytes.

  • -exec mv {} ...: The "action" part that moves every file found.


The "Quick & Dirty" Way (Using your original command)

If you prefer to stick to your ls command and just want to "eyeball" it, you can use head to move only the top largest files.

To move the top 5 largest files:

Bash
ls -pS | grep -v / | head -n 5 | xargs -I {} mv {} /path/to/destination/

Note: This version removes the -alh flags. When piping to mv, we don't want the "human-readable" sizes or permissions (like 1.2G or -rw-r--r--) included in the text, otherwise mv will get confused and think those are the filenames!


Comparison of Size Units

When using the -size flag in find, keep these suffixes in mind:

SuffixMeaningExample
kKilobytes-size +50k (Over 50 KB)
MMegabytes-size +10M (Over 10 MB)
GGigabytes-size +1G (Over 1 GB)
cBytes-size +100c (Over 100 Bytes)

Would you like me to show you how to do a "dry run" first, so you can see exactly which files will be moved before actually moving them?

 Yes, please. Thank you.

 

Performing a dry run is a pro move. It allows you to verify your logic without actually changing any files—saving you from that "oh no" moment when you accidentally move the wrong thing.

The simplest way to do a dry run is to replace the mv command with echo. This will print the command to your terminal instead of executing it.


1. Dry Run with the find Command

This is the safest way to test your size filters.

Bash
find . -maxdepth 1 -type f -size +100M -exec echo "Moving:" {} \;
  • What happens: The terminal will list every file larger than 100MB preceded by the word "Moving:". It won't actually move anything.

2. Dry Run with your ls Pipeline

If you are using the pipe method with xargs, just put echo before mv.

Bash
ls -pS | grep -v / | head -n 5 | xargs -I {} echo mv {} /path/to/destination/
  • What happens: You will see a list of commands like mv file1.zip /dest/. If the paths look correct, you can just hit the "Up" arrow on your keyboard and remove the echo to run it for real.


Comparison of Workflows

StepActionCommand Key
1. IdentifyList and filterfind or ls | grep
2. VerifyThe Dry Runecho
3. ExecuteFinal Movemv

A Quick Pro-Tip: The "Verbose" Flag

If you want to see the files moving while they are actually being moved (a middle ground between a dry run and flying blind), use the -v flag with mv:

Bash
mv -v source_file destination/
# Output: 'source_file' -> 'destination/source_file'

Would you like to know how to undo a move if you realize you sent files to the wrong folder?

 Yes, please. Thank you.

 

Moving files is instantaneous on the same disk, so there isn't a "Ctrl+Z" or "Undo" button in the terminal. However, you can effectively "reverse" the move by flipping the logic of your command.

Here are the best ways to handle an accidental move:

1. The "Reverse Move" (The Manual Fix)

If you just moved a specific group of files into a folder, the quickest way back is to go into that folder and move them back to the parent directory (represented by ..).

Bash
cd /path/to/destination/
mv * ../
  • Warning: Only do this if the destination folder was empty before you moved your files into it. Otherwise, you'll end up moving the original contents of that folder back to your source directory too!


2. The "By Time" Undo (The Precision Fix)

If you moved files into a folder that already had other files in it, you can use find to identify only the files that arrived in the last few minutes.

To move files out that arrived in the last 5 minutes:

Bash
find /path/to/destination/ -maxdepth 1 -type f -cmin -5 -exec mv {} ./ \;
  • -cmin -5: Finds files whose status changed (moved) less than 5 minutes ago.

  • ./: Moves them back to your current working directory.


3. Preventing Accidents: The "Interactive" Flag

To prevent needing an "undo" in the future, you can use the -i (interactive) flag. This forces the terminal to ask for your permission before overwriting any files at the destination.

Bash
mv -i source_file destination/
# Terminal: overwrite destination/source_file? (y/n)

Best Practices Summary

SituationSafety Strategy
Before movingUse echo for a Dry Run.
During the moveUse mv -v (Verbose) to see what's happening.
Potential OverwritesUse mv -n (No-clobber) to prevent overwriting existing files.
The "Undo"Use find with -cmin to isolate recently moved files.

Would you like me to show you how to create an "alias" so you can run these complex size-filtering moves with a single short command in the future?

 

 

 

 

25 January 2026

The list of all the format options of the gq command in vim?

In Vim, the
'formatoptions' setting controls how automatic text formatting is performed. It accepts a string of single-character flags, each enabling a specific behavior. You can view the current value in your Vim session with the command :set fo? or get a detailed explanation of all flags using the Vim help documentation via :help fo-table. 
The common and widely recognized formatoptions flags are:
  • t: Auto-wrap text at the width specified by the 'textwidth' option.
  • c: Auto-wrap comments at 'textwidth', automatically inserting the current comment leader character(s) (defined by 'comments' or 'commentstring').
  • q: Allow formatting with the gq operator.
  • r: Automatically insert the current comment leader after pressing <Enter> in Insert mode.
  • o: Automatically insert the current comment leader after pressing o or O in Normal mode.
  • n: Recognize numbered lists when formatting, using the pattern defined in 'formatlistpat'. This helps avoid joining list items into a single paragraph.
  • b: Auto-wrap text (backwards) when a line grows longer than 'textwidth'. The line is broken at the last white space before 'textwidth'.
  • v: Vi-compatible auto-wrapping (wraps at 'textwidth' in Insert mode).
  • j: Delete comment characters when joining lines using the J command.
  • l: Leave long lines as they are when entering Insert mode; only format if a line explicitly exceeds 'textwidth' due to typing.
  • m: Join with a space between the joined lines if there isn't one already.
  • p: Do not auto-wrap paste. When pasting text in Insert mode, do not apply auto-wrapping based on 'textwidth'.
  • u: Undo separate; make an undo command revert one line at a time instead of the entire paragraph formatting operation.
  • 2: Keep the indent of the second line when a paragraph is formatted (useful for some programming styles).
  • 1: Do not break a line after a single character (e.g., prevent single-letter words from being alone on the next line). 
  • a: Automatic formatting of paragraphs (changes are immediately reformatted). 
The default value is typically tcq. To add an option, you can use :set formatoptions+=<char>, and to remove one, use :set formatoptions-=<char>.